Adding Attachments to mail


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Adding Attachments to mail
# 1  
Old 03-16-2013
Adding Attachments to mail

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
# 2  
Old 03-16-2013
Here is how you can use sendmail to send HTML body along with an attachment:
Code:
{
        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.
# 3  
Old 03-16-2013
I recently did that in one of my assignment.
Use mutt instead
like
Code:
mutt -s "The Error Summary " -a $LOGDIR/ETL_ERR_SUMMARY.log $ETL_SUPPORT_MAIL_ID < $LOGDIR/mail_body.txt


Last edited by Franklin52; 03-17-2013 at 06:04 AM.. Reason: Code tags
# 4  
Old 03-18-2013
Thanks Yoda,
The solution provided by you helped me a lot.
Could you please elaborate me the functionality of boundary?

Thanks,
Durga
# 5  
Old 03-18-2013
Refer RFC 2046
# 6  
Old 03-18-2013
Thanks a lot Yoda
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Uuencode for mail attachments not working

Hi, I'm trying to send mail with attachments using uuencode, but it doesn't work. Command (also tried with mailx): uuencode testfile testfile | mail emailadress The email I get doesn't have an attachment, and has this in the message body: begin 664 testfile %=&5S=`H` ` end ... (4 Replies)
Discussion started by: Subbeh
4 Replies

2. Red Hat

How to send mail with multiple attachments?

We don't have uuencode installed in our machines..... Please tell me how to send mail with multiple attachments ??? URGENT !!!!! Please tell me using command line (or) scripts.......... please...... Thanks in Advance.... (1 Reply)
Discussion started by: vamshigvk475
1 Replies

3. Shell Programming and Scripting

Reading Mail attachments using unix

:wall:hi all, please somebody can help me out in reading the pop3 mail attachments or saving it locally i have a mail account where i receive .csv attachments i need to read that attachments and process them. any sample code can be much appriciated Removed email :wall: (3 Replies)
Discussion started by: srikanthkadapal
3 Replies

4. Shell Programming and Scripting

e-mail with multiple binary attachments!

Hi, I have to send email from UNIX with multiple excel attachments and the sender name needs to be customized (sender name need not to be UNIX user). I have checked many ways from this forum and other sources. But, nothing did work for me. Please help me! thanks, Raja. (1 Reply)
Discussion started by: smr_rashmy
1 Replies

5. UNIX for Advanced & Expert Users

Mail attachments getting corrupted...

Hi , Whenever I try to send mails with attachments to external email Id's the attachment is not encoded properly which appears along with body (text) of the mail. The attachement is always getting corrupted. Can anyone please suggest a solution. Regards, Sandipan (1 Reply)
Discussion started by: Sandipan
1 Replies

6. Solaris

mail with attachments

I want to send a mail with three attachments, but nothing happened. I tried it with mail and mailx. Are there special options for these commands or is it not possible to send mails under Solaris with attachments? Must there be special adjustments in the environment? Can anyone give an... (6 Replies)
Discussion started by: ninjadan
6 Replies

7. AIX

Send mail attachments and have a mail body

Hi, How can I send mail attachments from shell script (AIX) and have a mail body as well ? Thanks in advance. (1 Reply)
Discussion started by: shibajighosh
1 Replies

8. UNIX for Dummies Questions & Answers

sending attachments in mail

Hi , i have tried the following command to send an email with an attachment its working fine but i am getting mail with the embeded content inside the mail that too truncated. i wanted it as an attachment. /usr/lib/sendmail -F "MAC SIA" address "rajendra@abc.com.sg" -t <... (6 Replies)
Discussion started by: rajendragora
6 Replies

9. UNIX for Dummies Questions & Answers

file name got cut when using mail attachments

I am using the following command to send a zip file as an attachment to my internet email-id. uuencode ABC_DEFG_HIJ.zip ABC_DEFG_HIJ.zip | mail -s "attachment from shell" pal@yahoo.com Eventhough i have given the attached file as 'ABC_DEFG_HIJ.zip', when i receive the mail in my internet... (3 Replies)
Discussion started by: Pal
3 Replies

10. UNIX for Dummies Questions & Answers

mail attachments

I'm writing scripts on HP-UX. Is there a way to attach a file to a mail message. I don't want to imbed the data in the mail message. (1 Reply)
Discussion started by: Multithreaded
1 Replies
Login or Register to Ask a Question