Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send HTML body email with multiple text attachments using sendmail

Tags:

unix

sendmail

I want to send a HTML file as message body and want to attach multiple text files to this email message.

Since html file needs to be sent, sendmail has to be used ( I could not do it using mailx ).

How do you send HTML body email and multiple text attachments using sendmail?

like image 704
vaichidrewar Avatar asked Mar 22 '11 17:03

vaichidrewar


People also ask

How do I email multiple attachments?

We can include multiple attachments by separating them using a semicolon.


1 Answers

Assuming you have uunecode available in your system you can send email with multiple attachments like this:

#!/bin/bash

...
...
...
BOUNDARY="=== This is the boundary between parts of the message. ==="

{
   echo  "From: $MAILFROM"
   echo  "To: $MAILTO"
   echo  "Subject:" $SUBJECT
   echo  "MIME-Version: 1.0"
   echo  "Content-Type: MULTIPART/MIXED; "
   echo  "    BOUNDARY="\"$BOUNDARY\"
   echo
   echo  "        This message is in MIME format.  But if you can see this,"
   echo  "        you aren't using a MIME aware mail program.  You shouldn't "
   echo  "        have too many problems because this message is entirely in"
   echo  "        ASCII and is designed to be somewhat readable with old "
   echo  "        mail software."
   echo
   echo  "--${BOUNDARY}"
   echo  "Content-Type: TEXT/PLAIN; charset=US-ASCII"
   echo
   echo  "This email comes with multiple attachments."
   echo
   echo
   echo  "--${BOUNDARY}"
   echo  "Content-Type: application/zip; charset=US-ASCII; name="${ZIPFILE}
   echo  "Content-Disposition: attachment;   filename="`basename ${ZIPFILE}`
   echo
   uuencode $ZIPFILE $ZIPFILE
   echo
   echo  "--${BOUNDARY}--"
   echo  "Content-Type: application/pdf; charset=US-ASCII; name="${PDFFILE}
   echo  "Content-Disposition: attachment;   filename="`basename ${PDFFILE}`
   echo  
   uuencode $PDFFILE $PDFFILE
   echo
   echo  "--${BOUNDARY}--"
} | /usr/lib/sendmail -t
like image 158
anubhava Avatar answered Nov 09 '22 20:11

anubhava