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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Mail sending with multiple attachement(pdf and csv) with html content from Linux
# 1  
Old 11-22-2013
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.
Code:
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


Last edited by Franklin52; 11-22-2013 at 04:19 AM.. Reason: Please use code tags
# 2  
Old 11-22-2013
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
Code:
mutt -a first_attachment -a second_attachment ...

# 3  
Old 11-22-2013
Mail sending with multiple attachement(pdf and csv) with html content from Linux

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.
# 4  
Old 11-22-2013
You can try
Code:
mutt -e 'my_hdr Content-Type: text/html' ... < your_html

or
Code:
 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
# 5  
Old 11-22-2013
Try this instead:
Code:
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

# 6  
Old 11-22-2013
Quite a few modern email clients do not understand uuencode, just base64, I found a perl script which can do that:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need help in sending html mail with attachment

Hi Everyone, I am facing problems in sending html mail with attachemnt. I will able to send mail with attachment (plain text ) using mailx -s and uuencode command and also html mail without attachment using sendmail option. However I am not able to send html mail along with attachment.Either... (2 Replies)
Discussion started by: karthik adiga
2 Replies

2. Shell Programming and Scripting

Sending csv file as an attachement from Linux

Hi i am trying to send a csv file as an attachment via mail from linux. i am using the below script. echo "X-Mailer: htmlmail" $VERSION echo "Mime-Version: 1.0" echo 'Content-Type: multipart/mixed; boundary="-q1w2e3r4t5"' echo '---q1w2e3r4t5' echo "Content-Type: text/html; charset=US-ASCII"... (1 Reply)
Discussion started by: mohanalakshmi
1 Replies

3. UNIX for Advanced & Expert Users

Mutt for html body and multiple html & pdf attachments

Hi all: Been racking my brain on this for the last couple of days and what has been most frustrating is that this is the last piece I need to complete a project. There are numerous posts discussing mutt in this forum and others but I have been unable to find similar issues. Running with... (1 Reply)
Discussion started by: raggmopp
1 Replies

4. Shell Programming and Scripting

Sending a csv attachment and html text together.

Hello, I need to send below text (in a file ABC)as html text in mail body and the same as csv attachment 1,2,3 4,5,6 7,8,9 but to send as html text in mailbody we use echo "Subject: Report " | cat - ABC | /usr/lib/sendmail -t a@xyz.com and to send as an attachment in csv format we... (9 Replies)
Discussion started by: skhichi
9 Replies

5. Shell Programming and Scripting

How to embed a html file in a mail sending from Linux box with uuencode or mailx?

How to embed a html file as subject in a mail sending from Linux box with uuencode or mailx or any other way? we do not want the file as attachment, it should be embedded in the mail subject. (2 Replies)
Discussion started by: johnveslin
2 Replies

6. Shell Programming and Scripting

sending attachement in mail

Hi , I am using the below code to send mail through a script which run as a cron job. msgdate=`date +"%a, %e %Y %T %z"` daemail=$(cat <<! From: $from To: $emailtarget Subject: $subject Mime-Version: 1.0 Content-Type: multipart/mixed; Content-Disposition: inline $priority $CONTENT !)... (2 Replies)
Discussion started by: ahamed
2 Replies

7. Shell Programming and Scripting

Sending HTML attachment through mail

Hi I am new to unix and scripting.I am trying to send a html file as an attachment. SUBJECT="Type of Exceptions in Application" TO=Sushovan.Samals@gmail.com SPOOLFILE=/data/reg/tlogs/Monitor.html #echo "Send the E-mail message..." uuencode $SPOOLFILE $SPOOLFILE | mailx -s "$SUBJECT" $TO... (2 Replies)
Discussion started by: sushovan
2 Replies

8. UNIX for Dummies Questions & Answers

sending mail with html content

hi, I am new to unix. I need send html content as a mail from my sun-solaris2.6 work station. When I tried that the recipient gets it as html code with all the tags. any solutions? thanx in advance (2 Replies)
Discussion started by: gmchoudary
2 Replies

9. Shell Programming and Scripting

mail: html content

hi guys, am required to prepare a report and mail it, to make it more appealing :p i wish to have content of mail in rich text format i.e html type with mailx how to specify the content type of mail body as html? Thanks in advance!!! rishi (2 Replies)
Discussion started by: RishiPahuja
2 Replies

10. Shell Programming and Scripting

Sending mail from Unix - For html output

I have automated some checks - and I want to send a email when there is an issue. This is fine and I can send the email. However - I want to generate the email in html format so I can highlight any issues to a reader.. ie. If there is a disk space issue - then the email will highlight the... (2 Replies)
Discussion started by: frustrated1
2 Replies
Login or Register to Ask a Question