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
No related posts.
Related posts brought to you by Yet Another Related Posts Plugin.







Great articles & Nice site…i’ve bookmarked it already
[Reply]
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
[Reply]