Mail sending with multiple attachement(pdf and csv) with html content from Linux

Hi,

We have a requirement to send multiple attachment(pdf and csv) along with html content in a single mail. For that we are using uuencode. It is working for single pdf attachment and html content. But we are unable to send both pdf and csv attachment with html content. Below is the script. Please help. Thanks in advance.

 
export MAILFROM="donotreply@DMZ.com"
export MAILTO=$EMAIL_ID
export SUBJECT="Your Invoice"
export BODY="$BIP_MAIL/dmz_Tax_Invoice.html"
export ATTACH="$BIP_PDF_FILE_PATH/B1-18142.pdf"
export MAILPART=`uuidgen` ## Generates Unique ID
export MAILPART_BODY=`uuidgen` ## Generates Unique ID
 
(
 echo "From: $MAILFROM"
 echo "To: $MAILTO"
 echo "Subject: $SUBJECT"
 echo "MIME-Version: 1.0"
 echo "Content-Type: multipart/mixed; boundary=\"$MAILPART\""
 echo ""
 echo "--$MAILPART"
 echo "Content-Type: multipart/alternative; boundary=\"$MAILPART_BODY\""
 echo ""
 echo "--$MAILPART_BODY"
 echo "Content-Type: text/plain; charset=ISO-8859-1"
 echo "You need to enable HTML option for email"
 echo "--$MAILPART_BODY"
 echo "Content-Type: text/html; charset=ISO-8859-1"
 echo "Content-Disposition: inline"
 cat $BODY
 echo "--$MAILPART_BODY--"
 
 echo "--$MAILPART"
 echo 'Content-Type: application/pdf; name="'$(basename $ATTACH)'"'
 echo "Content-Transfer-Encoding: uuencode"
 echo 'Content-Disposition: attachment; filename="'$(basename $ATTACH)'"'
 echo ""
 #uuencode -m $ATTACH $(basename $ATTACH)
 uuencode $ATTACH $(basename $ATTACH)
 echo "--$MAILPART--"
) | /usr/sbin/sendmail $MAILTO

You should check the command mutt.
I never used, so I might be wrong, but if a I remember correctly, you should be able to add multiple attachment to the email. Something like

mutt -a first_attachment -a second_attachment ...

Thanks. I have alrady tried it with mutt. I can send multiple attachments using mutt, but can not send it with html content.

Please let me know if there any option to send html content with multiple attachment using mutt.

You can try

mutt -e 'my_hdr Content-Type: text/html' ... < your_html

or

 mutt -e "set content_type=text/html ... < your_html"

In some version of mutt these works. But honestly I just google it because I was curious, I never tried it, so it might won't work. Sorry

Try this instead:

export MAILFROM="donotreply@DMZ.com"
export MAILTO="$EMAIL_ID"
export SUBJECT="Your Invoice"
export BODY="$BIP_MAIL/dmz_Tax_Invoice.html"
export ATTACH_PDF="$BIP_PDF_FILE_PATH/B1-18142.pdf"
export ATTACH_CSV="csv_path/your_csv_file.csv"

pdf_file=$( basename "$ATTACH_PDF" )
csv_file=$( basename "$ATTACH_CSV" )

{
        echo "From: $MAILFROM"
        echo "To: $MAILTO"
        echo "MIME-Version: 1.0"
        echo "Subject: $SUBJECT"
        echo "Content-Type: multipart/mixed; boundary=\"FILEBOUNDARY\""
        
        echo "--FILEBOUNDARY"
        echo "Content-Type: multipart/alternative; boundary=\"MSGBOUNDARY\""
        
        echo "--MSGBOUNDARY"
        echo "Content-Type: text/html; charset=iso-8859-1"
        echo "Content-Disposition: inline"
        cat "$BODY"
        echo "--MSGBOUNDARY--"
        
        echo "--FILEBOUNDARY"
        echo "Content-Type: application/pdf"
        echo "Content-Disposition: inline; filename=\"${pdf_file}\""
        echo "Content-Transfer-Encoding: uuencode"
        uuencode "$ATTACH_PDF" "$pdf_file"
        echo "--FILEBOUNDARY"
        echo "Content-Type: text/csv"
        echo "Content-Disposition: inline; filename=\"${csv_file}\""
        echo "Content-Transfer-Encoding: uuencode"
        uuencode "$ATTACH_CSV" "$csv_file"
        echo "--FILEBOUNDARY--"
} | /usr/sbin/sendmail -t

Quite a few modern email clients do not understand uuencode, just base64, I found a perl script which can do that: