Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What's wrong with my code?

Status
Not open for further replies.

volcano

Programmer
Aug 29, 2000
136
HK
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
 
Correct me if I'm print, but PDF is a binary format. Your email is indicating that it's a base64 encoding, but you're not converting the file to base64, you're just spewing it straight into the mail.

A quick check of Bull and sourceforge didn't turn up anything that might be useful.
 
I think you need to uuencode the pdf file into another file then cat that to the email.
 
Thanks so much for all of your advice..finally I can solve the problem. The solution is to use &quot;MIMENCODE&quot; command (or other similar encoding tools) to encode the PDF instead of using &quot;CAT&quot; command...once this line is changed, I can send and receive the PDF successfully..

Thanks again for your help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top