sendmail with attachments


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sendmail with attachments
# 8  
Old 09-10-2009
I have a play around with the script and the following works: (a fluke obviously!)

1. HTML email body (in this case defined within the Shell Script)
2. Multiple attachments (HTML Excel etc)
3. All working correctly with no encoding problems or error messages!

Code:
export MAILTO="someone@somewhere.com"
export SUBJECT="$EMAIL_SUBJECT"
export BODY="$EMAIL_FILE"
export ATTACH="$HTML_FILE"
export ATTACH1="$EXCEL_FILE1"
export ATTACH2="$EXCEL_FILE2"
export ATTACH3="$EXCEL_FILE3"
(
 echo "To: $MAILTO"
 echo "Subject: $SUBJECT"
 echo "MIME-Version: 1.0"
 echo 'Content-Type: multipart/mixed; boundary="-q1w2e3r4t5"'
 echo
 echo '---q1w2e3r4t5'
 echo "Content-Type: text/html"
 echo "Content-Disposition: inline"
 cat $BODY 
 echo '---q1w2e3r4t5'
 echo 'Content-Type: application; name="'$(basename $ATTACH)'"'
 echo "Content-Transfer-Encoding: uuencode" 
 echo 'Content-Disposition: attachment; filename="'$(basename $ATTACH)'"'
 echo '---q1w2e3r4t5--'
 uuencode $ATTACH $(basename $ATTACH)
 echo '---q1w2e3r4t5'
 echo 'Content-Type: application; name="'$(basename $ATTACH1)'"'
 echo "Content-Transfer-Encoding: uuencode" 
 echo 'Content-Disposition: attachment; filename="'$(basename $ATTACH1)'"'
 echo '---q1w2e3r4t5--'
 uuencode $ATTACH1 $(basename $ATTACH1)
  echo '---q1w2e3r4t5'
 echo 'Content-Type: application; name="'$(basename $ATTACH2)'"'
 echo "Content-Transfer-Encoding: uuencode" 
 echo 'Content-Disposition: attachment; filename="'$(basename $ATTACH2)'"'
 echo '---q1w2e3r4t5--'
 uuencode $ATTACH2 $(basename $ATTACH2)
  echo '---q1w2e3r4t5'
 echo 'Content-Type: application; name="'$(basename $ATTACH3)'"'
 echo "Content-Transfer-Encoding: uuencode" 
 echo 'Content-Disposition: attachment; filename="'$(basename $ATTACH3)'"'
 echo '---q1w2e3r4t5--'
 uuencode $ATTACH3 $(basename $ATTACH3) 
) | /usr/sbin/sendmail $MAILTO

Thanks for your help Ygor, would never have got this without your code.

Last edited by Scott; 01-05-2010 at 11:41 PM.. Reason: Added code tags
# 9  
Old 11-13-2009
Great script that you so much

I'm trying to also embed an image to the email with no luck and wondering if you can help me, here is KSH i'm using:
Code:
export MAILTO=myemail@me.com
export FROM="me@me.com"
export SUBJECT="Test"
export BODY="index_image.htm"
ATTACH=$1
export ATTACH1="WirelessEmail1.jpg"
(
echo "To: $MAILTO"
echo "FROM: $FROM"
echo "Subject: $SUBJECT"
echo "MIME-Version: 1.0"
echo 'Content-Type: multipart/mixed; boundary="-q1w2e3r4t5"'
echo
echo '---q1w2e3r4t5'
echo "Content-Type: text/html"
echo "Content-Disposition: inline"
cat $BODY
echo '---q1w2e3r4t5'
echo 'Content-Type: image/jpeg; filename="WirelessEmail1.jpg"'
echo "Content-Disposition: inline"
echo "Content-Transfer-Encoding: base64"
echo "Content-ID: <myimage.jpg>"
echo '---q1w2e3r4t5'
echo 'Content-Type: application; name="'$(basename $ATTACH)'"'
echo "Content-Transfer-Encoding: uuencode"
echo 'Content-Disposition: attachment; filename="'$(basename $ATTACH)'"'
echo '---q1w2e3r4t5--'
uuencode $ATTACH $(basename $ATTACH)
) | /usr/sbin/sendmail $MAILTO

I do receive an email with attached PDF but the image does not show in HTML body, the following shows up between the HTML body and the attached PDF file:
Content-Type: image/jpeg; filename="WirelessEmail1.jpg" Content-Disposition: inline Content-Transfer-Encoding: base64

I tried Google and other posts on this site but couldn't figure out how to embed this image, any help would be appreciated, thank you

Last edited by Scott; 01-05-2010 at 11:41 PM.. Reason: Added code tags
# 10  
Old 11-16-2009
Not sure what your $1 variable is. I would try:
Code:
export MAILTO=myemail@me.com
export FROM="me@me.com"
export SUBJECT="Test"
export BODY="index_image.htm"
export ATTACH="WirelessEmail1.jpg"
(
echo "To: $MAILTO"
echo "FROM: $FROM"
echo "Subject: $SUBJECT"
echo "MIME-Version: 1.0"
echo 'Content-Type: multipart/mixed; boundary="-q1w2e3r4t5"'
echo
echo '---q1w2e3r4t5'
echo "Content-Type: text/html"
echo "Content-Disposition: inline"
cat $BODY
echo '---q1w2e3r4t5'
echo 'Content-Type: image/jpeg; filename="WirelessEmail1.jpg"'
echo "Content-Disposition: inline"
echo "Content-Transfer-Encoding: base64"
echo "Content-ID: <myimage.jpg>"
echo '---q1w2e3r4t5'
echo 'Content-Type: application; name="'$(basename $ATTACH)'"'
echo "Content-Transfer-Encoding: uuencode"
echo 'Content-Disposition: attachment; filename="'$(basename $ATTACH)'"'
echo '---q1w2e3r4t5--'
uuencode $ATTACH $(basename $ATTACH)
) | /usr/sbin/sendmail $MAILTO


Last edited by Scott; 01-05-2010 at 11:42 PM.. Reason: Added code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Sendmail - Attachments & Subjects

Hi All, Not been around in a while. However I have been all over tinternet (google) for days looking for a solution. Where I work has decided to use Sendmail on our Linux and Unix estate for sending emails via scripts. So I am hoping to eventually get a working solution for Sendmail and not... (3 Replies)
Discussion started by: dakelly
3 Replies

2. Solaris

Clarifying sendmail configuration - sendmail-client offline

Hi all, I have read about sendmail running as 2 separate process. 1 as a MSP, and the other as the real daemon or MTA. In my current configuration, the sendmail-client is disabled. Both submit.cf and sendmail.cf are left as default untouch I do not specified any mailhost... (3 Replies)
Discussion started by: javanoob
3 Replies

3. Shell Programming and Scripting

Mailing multiple PNG attachments using sendmail

Need assistance in using the below script and having multiple png file attachments in the same script . Your inputs are appreciated. I dont have uuencode , I use either mailx, sendmail, mpack . ( echo "to: samplemail@somewhere.com" echo "from: samplemail@elsewhere.com" echo "subject:... (2 Replies)
Discussion started by: ajayram_arya
2 Replies

4. UNIX for Advanced & Expert Users

Sendmail questions, SCO 5.0.6 sendmail 8.11.0

I am running SCO 5.0.6 and using sendmail 8.11.0 and having issues with smtp authentication. When trying to send mail the following message will kick back. (reason: 530 5.7.1 Authentication required) 530 5.7.1 Authentication required Not sure what needs to be tweeked in sendmail.cf but I... (1 Reply)
Discussion started by: ziggy6
1 Replies

5. Shell Programming and Scripting

Sendmail gz Attachments

Hi All, I have a problem again with sendmail content type . I am trying to attach the gz file to the html email but couldnt figure out even after extensive google. Here is my code. ( echo "From: $FROM" echo "To: $MAILTO" echo... (3 Replies)
Discussion started by: posner
3 Replies

6. Shell Programming and Scripting

Sendmail Png Attachments

I use sendmail to send html emails, my script works perfect and sends email with plain text attachment. Now i need to attache png file to the email and this attachment part is not working. ( echo "From: $FROM" echo "To: $TO" echo "MIME-Version: 1.0" echo "Subject: $SUBJECT" echo... (4 Replies)
Discussion started by: posner
4 Replies

7. Shell Programming and Scripting

Sendmail Script: Gmail cannot find attachments

Hi. I am using a script on HP-UX to send emails that include a Pdf attachment to clients. The scipt makes use of sendmail. The scripts works for everything except gmail. When I go on gmail via my Web Browser, I can see the message with the attachment, but if I try to view or download the... (2 Replies)
Discussion started by: Wahooka
2 Replies

8. UNIX and Linux Applications

Attachments in MUTT.

Can any body figure out how to attach the attachments mails while drafting them in MUTT form any location on my system. I am not able to figure it out. (0 Replies)
Discussion started by: nixhead
0 Replies

9. UNIX for Dummies Questions & Answers

sendmail attachments

Dear all, I've been working with AIX for, um, 15 years now and I have read all I can about the above, but I am stuck. Everything seems to point to using sendmail on the command line to embed a uuencoded attatchment will not work. Using something like "(cat plain.txt;uuencode attach.file... (4 Replies)
Discussion started by: rbatte1
4 Replies

10. Post Here to Contact Site Administrators and Moderators

Attachments

Hi I find that the attachment size are very limited. For eg, if we wish to analyse explorers from Sun systems or messages file, definitely they will exceed the given 3.5MB .. Dun you think so?:p (6 Replies)
Discussion started by: incredible
6 Replies
Login or Register to Ask a Question