Sendmail from script

From thelinuxwiki
Revision as of 14:41, 16 February 2014 by Nighthawk (Talk | contribs)

Jump to: navigation, search

how to send mail from a script on a mail server

example #1 using the postfix sendmail binary

    echo "Subject: Testing" | cat - /var/tmp/test_message_body.txt | /usr/sbin/sendmail -F me@overhere.com you@overthere.com
    or use \n to separate subject from message body
    echo "Subject: Testing\nMessage body!" | /usr/sbin/sendmail -F me@overhere.com you@overthere.com

example #2 using the postfix sendmail binary

    echo "Subject: Testing" | /usr/sbin/sendmail -F me@overhere.com you@overthere.com

example #3 using mailx

    echo "my test message body " | mail -s "what you are" yourfriend@somewhere.com

example #4

    mail -F me@overhere.com you@overthere.com < message.txt

where the contents of message.txt are:

SUBJECT:Testing some mail stuff

blah blah blah message text

.

      • note mail is a link to sendmail