Created
June 15, 2015 10:52
-
-
Save kgaughan/d1498b42156ecb89980f to your computer and use it in GitHub Desktop.
Sending an email from the shell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# To send a email, use the 'mailx' command. This takes the email to send on | |
# standard input. The -s flag is used to specify your subject, and the | |
# recipient address is specified without any flags. Everything after '--' is | |
# passed on to the Mail Transport Agent (MTA, the local mailserver), and the | |
# '-f' flag is used to specify the sender address, while '-F' is used to | |
# specify the sender name. | |
# | |
# See 'man 1 mailx' for details. The Debian packages you can use for this are | |
# 'bsd-mailx' or 'heirloom-mailx', though both present slightly different | |
# command line interfaces. I'm using 'bsd-mailx' here. | |
mailx -s "My subject" [email protected] -- -F "Jane Doe" -f [email protected] <<END | |
This is my email, and it's in a heredoc! | |
END | |
# To add an attachment, the simplest method is to uuencode the attachment. | |
# UU-encoded attachments can be put anywhere in the email. 'uuencode' itself | |
# takes two arguments: the full path of the attachment and the filename to use | |
# for the attachment in the email. Here's an example. | |
my_attachment=/path/to/my/attachment | |
attachment_name=$(basename $my_attachment) | |
mailx -s "My subject" [email protected] -- -F "Jane Doe" -f [email protected] <<END | |
I'm sending you something very useful. | |
$(uuencode $my_attachment $attachment_name) | |
END |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment