RSS

[unix] Send mail from the command line using mail and sendmail commands

12 Nov

1. If the message isn’t too long then type the following in the commandline and hit enter

$ mail -s "Subject of the email" -c cc_recipient@domain1.com -b bcc_recipient@domain2.com main_recipient@domain3.com -- -F"Sender Name" -fSender@domain4.com

Then keep typing your message. To send it either enter a blank line with just a single period (“ . ”’) in it and hit enter again, or just hit control+d. That’s it! A email to main_recipient@domain3.com has been sent with a carbon copy (cc) to cc_recipient@domain1.com and a blind carbon copy (bcc) to bcc_recipient@domain2.com. The recipients will see the message from “Sender Name” who has email address Sender@domain4.com.

The sendmail flags (-f and -F) come after the -- sign. Notice that there is no space between the sendmail flags and the corresponding arguments.

Needless to say, you may skip the cc and bcc fields.

2. If the message is fairly long you may want to compose it in a text file, say message.txt, using a convenient editor. Send the email with the body of the email as the text in message.txt as follows

$ mail -s "Subject of the email" -c cc_recipient@domain1.com -b bcc_recipient@domain2.com main_recipient@domain3.com -- -F"Sender Name" -f sender@domain4.com < message.txt

3. In order to send a file as attachement (say, attachment.pdf) use the following

$ uuencode attachment.pdf  attachment_name_that_the_reciepents_will_see.pdf | mail -s "Subject of the email" -c cc_recipient@domain1.com -b bcc_recipient@domain2.com main_recipient@domain3.com -- -F"Sender Name" -f sender@domain4.com < message.txt

Update: If -F and -f flags are used together only -f and its argument are used. Weird!

About these ads
 
Leave a comment

Posted by on November 12, 2012 in linux, unix

 

Tags: ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.

Join 31 other followers

%d bloggers like this: