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 |
Related posts:
- How to change admin email address @boxXXX.bluehost.com to @mydomain.com on a bluehost hosted wordpress I currently have hosting through bluehost.com. I was surprised to...
- Grep for multiple stuff in one file Update: See the comments to see how to do this...
- comment multiple lines in vi The comment symbol for Unix scripts is typically “#”. You...
Related posts brought to you by Yet Another Related Posts Plugin.







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