Hi,
I need to send a mail with html code in body and an attachment along with the body and subject.
The html code must display a table with data in it in the mail.
I have tried the 'sendmail' command, but I am am able to display the table in the mail and unable to attach an attachment.
Also tried with mailx, but able to attach an attachment but failed with HTML code.
Please help me with this if there is anyway I can dothat.
Thanks,
Durga
Yoda
2
Here is how you can use sendmail to send HTML body along with an attachment:
{
echo "From: from_user@domain.com"
echo "To: to_user@domain.com"
echo "MIME-Version: 1.0"
echo "Subject: Email Subject"
echo 'Content-Type: multipart/mixed; boundary="-q1w2e3r4t5"'
echo "---q1w2e3r4t5"
echo "Content-Type: text/html"
echo "Content-Disposition: inline"
echo '---q1w2e3r4t5'
cat html_file
echo '---q1w2e3r4t5'
echo "Content-Type: text/plain; charset=US-ASCII; name=attachment_file"
echo "Content-Disposition: attachment; filename=attachment_file"
echo '---q1w2e3r4t5'
cat attachment_file
echo '---q1w2e3r4t5--'
} | /usr/lib/sendmail -t
Note: Replace html_file
with your HTML file name or HTML code. Replace attachment_file
with the file name that you want to attach.
I recently did that in one of my assignment.
Use mutt instead
like
mutt -s "The Error Summary " -a $LOGDIR/ETL_ERR_SUMMARY.log $ETL_SUPPORT_MAIL_ID < $LOGDIR/mail_body.txt
Thanks Yoda,
The solution provided by you helped me a lot.
Could you please elaborate me the functionality of boundary?
Thanks,
Durga