Hello, I have a trouble in sending email attachment. Your advice is very much appreciated!
My problem is that I have written a shell script to send an PDF to a client. However when I executed the script, he could receive the PDF but couldn't open it. It seemed the PDF was damaged. Therefore I would like to post my script here and see if you professionals can give me any advice~
Thanks
---
{
echo 'To: client@test.com'
echo 'From: me@test.com'
echo 'Subject: test attachment'
echo 'MIME-Version: 1.0'
echo 'Content-Type: multipart/mixed; boundary="xxxxyyyyzzzz"'
echo ''
echo '--xxxxyyyyzzzz'
echo 'Content-Type: text/plain'
echo ''
echo 'There should be an attachment of pdf'
echo ''
echo '--xxxxyyyyzzzz'
echo 'Content-Type: application/octet-stream; name="test.pdf"'
echo 'Content-Transfer-Encoding: base64'
echo 'Content-Disposition: attachment; filename="test.pdf"'
echo ''
cat $PWD/test.pdf
echo ''
echo '--xxxxyyyyzzzz--'
echo ''
echo '.'
} > test.txt
/usr/lib/sendmail -t -n < test.txt
My problem is that I have written a shell script to send an PDF to a client. However when I executed the script, he could receive the PDF but couldn't open it. It seemed the PDF was damaged. Therefore I would like to post my script here and see if you professionals can give me any advice~
Thanks
---
{
echo 'To: client@test.com'
echo 'From: me@test.com'
echo 'Subject: test attachment'
echo 'MIME-Version: 1.0'
echo 'Content-Type: multipart/mixed; boundary="xxxxyyyyzzzz"'
echo ''
echo '--xxxxyyyyzzzz'
echo 'Content-Type: text/plain'
echo ''
echo 'There should be an attachment of pdf'
echo ''
echo '--xxxxyyyyzzzz'
echo 'Content-Type: application/octet-stream; name="test.pdf"'
echo 'Content-Transfer-Encoding: base64'
echo 'Content-Disposition: attachment; filename="test.pdf"'
echo ''
cat $PWD/test.pdf
echo ''
echo '--xxxxyyyyzzzz--'
echo ''
echo '.'
} > test.txt
/usr/lib/sendmail -t -n < test.txt