Saturday, October 24, 2009

Sending mails using the command line

First check. whether Sendmail is running;

#/etc/init.d/sendmail status

if the status shows that it;s not, then start it;
#/etc/init.d/sendmail restart

then , send mails using either the mail or mutt command;

#ehco "body of the mail" | ,ail -s "Subject of the mail" toAddress

Give the recipient's mail ID in place of toAddress.
As for the body of the mail, you can also redirect it from a file, as follows,
#mail -s "subject of the mail" toAddress < body_mail.txt
If u want to send a file as an attachment, you can use mutt instead:

#echo "body of the mail" | mutt -s "subecjt of the mail" \-a fileToAttach.txt toAddress


Give the recipient's email ID in place of toAddress.