Sendmail from script

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

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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 "my subject" 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