Frequently Asked Questions

« Previous
How do snapshots in the HNAS file server work?
Next »
I have installed R in another location. How do I use it in a script?

windows ubuntu macos xibo network zenworks android storage



113. 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.

FROM=helpdesk@bmc.uu.se TO=jerker.nyberg@bmc.uu.se 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

FROM=helpdesk@bmc.uu.se TO=jerker.nyberg@bmc.uu.se 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 2017-06-22

   

This documentation is covered by GNU Free Documentation License.