Categories

 

March 2010
M T W T F S S
« Feb   Apr »
1234567
891011121314
15161718192021
22232425262728
293031  

What I'm Doing...

PlaytimePriya and KunalIMG00015.jpgIMG00017.jpgFallColors.jpgSpring

Sending email with a body and attachment from UNIX

It is easy to send a text file as the body of an email from UNIX. You can do it using the command below

mail -s "Email with file as body" email@domain.com < message.txt

Now if you want to send a file as an attachment, you would need to use uuencode piped to mail. This file can be a binary file or a text file. The command is

uuencode file.dat file.dat | mail -s "Email with attachment" email@domain.com

Suppose you want to send an email with a body and an attachement. Here is the trick –

First create the attachment file by using uuencode. Then join the message file which is the body of the email along with the uuencoded file which is going to be an attachment by using the cat command.

uuencode file.dat file.dat > attachment.txt
cat message.txt attachment.txt > combined.txt

Now all you need do is to send the email using the first method shown here

mail -s "Email with message body and attachment" email@domain.com < combined.txt
Share

No related posts.

Related posts brought to you by Yet Another Related Posts Plugin.

2 comments to Sending email with a body and attachment from UNIX

  • Gaylene Wyckoff

    Great articles & Nice site…i’ve bookmarked it already

    ReplyReply

    [Reply]

  • Patrick

    Hey Srini, I’m trying to solve an email issue with AUTOSYS, while searching the web I came across your site….pretty cool…
    similar to how you say to do this on your site I’m running this command from the cmd line and no problem it works great, but when I ran from AUTOSYS it didn’t work….any ideas?
    /usr/bin/uuencode /localvision/update/RawData/Data/Factset/GAA_DAILY_0.ZIP GAA_DAILY_0.ZIP | mail -s “GAA.zip Daily” patrick_travis@ssga.com
    I do get this error when I run it from the cmd line:
    Non-null variable name required
    but it still runs fine

    ReplyReply

    [Reply]

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>