Categories

 

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

What I'm Doing...

IMG00015.jpgIMG00017.jpgFallColors.jpgSpringFirst snow of the seasonTail Wind

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/Bookmark

Related posts:

  1. 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...
  2. Grep for multiple stuff in one file Update: See the comments to see how to do this...
  3. 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.

1 comment to Sending email with a body and attachment from UNIX

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>

Powered by WP Hashcash