Frequently Asked Questions

« Previous
What fun things can I do with Systemd in Linux?
Next »
How do I change the Mac computer name, host name and NetBIOS-name?

windows ubuntu macos xibo network zenworks android storage

107. How do I send mail from a shell script in Linux and macOS?

See also: How do I lookup LDAP or Active Directory via command line on Mac and Linux?

Here is an example of sending mail on Linux and MacOS, one using sendmail and one using mailx.

The sendmail binary may be both in /usr/sbin/sendmail and the traditional /usr/lib/sendmail but using the /usr/bin/env as a wrapper should work with both location.

Please note that both the envelope header and the from-header must be set. This is done with sendmail both inside the mail and as a command line argument. There are other ways of doing this. But this is one of them. SUBJECT="This is in subject" /usr/bin/env sendmail -f $FROM $TO <<EOF To: $TO From: $FROM Subject: $SUBJECT Hello darkness my old friend! EOF SUBJECT="This is in subject" /usr/bin/mailx -s "$SUBJECT" -r $FROM $TO <<EOF Hello darkness my old friend! EOF


This entry sendmail was last modified 2018-06-04


This documentation is covered by GNU Free Documentation License. 12 ms