Mail command

22 02 2009

Simple way for using command line mail program on Linux:

Syntax:
mail -s “Subject” -a attach_file.txt -r sender@domain -S smtp=ip-of-smtp-address destination@domain < file_of_message_body

Sample:
/usr/bin/mail -s “List logs today” -a /root/logs/listlogs.txt -r backup@domain.net -S smtp=192.168.169.5 adinda@domain.co.id < /root/logs/listlogs.txt

OR The other way is:

Simple Email Message:

echo “Message Body” | mail -s “Subject” receiver@emailaddress.com

Sending File using Linux mail command:

mail -s “Subject” receiver@emailaddress.com < file_to_send.txt

Sending Binary Files with Linux mail command:
Sometimes sending binary files does not work well the command line. We can use uuencode formatting for sending such files:

uuencode myimage.jpeg | mail -s “Subject” receiver@emailaddress.com

Few command line options for Linux mail command:

-s subject ~ Use subject for the e-mail title
-r reply email address ~ email address if you reply to
-c cc email address ~ Send copy of the mail to the specified address
-b bcc emailaddress ~ Send blind carbon copy to specified address
-a attachment file ~ I try just only text file
-S (capital S) for smtp address ~ you could change to other smtp address


Actions

Information

Leave a comment