[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 -b -- -F"Sender Name"

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 has been sent with a carbon copy (cc) to and a blind carbon copy (bcc) to The recipients will see the message from “Sender Name” who has email address

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 -b -- -F"Sender Name" -f < 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 -b -- -F"Sender Name" -f < 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: Logo

You are commenting using your 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


Get every new post delivered to your Inbox.

Join 35 other followers

%d bloggers like this: