# msgid "" msgstr "" msgid "" "title: Send emails using the command line for fun and profit!\n" "date: 2020-09-04\n" "layout: post\n" "lang: en\n" "ref: send-emails-using-the-command-line-for-fun-and-profit" msgstr "" msgid "Here are a few reasons why:" msgstr "" msgid "" "send yourself and other people notification of cronjobs, scripts runs, CI " "jobs, *etc.*" msgstr "" msgid "leverage the POSIX pipe `|`, and pipe emails away!" msgstr "" msgid "because you can." msgstr "" msgid "Reason 3 is the fun part, reasons 1 and 2 are the profit part." msgstr "" msgid "" "First [install and configure " "SSMTP](https://wiki.archlinux.org/index.php/SSMTP) for using, say, Gmail as " "the email server:" msgstr "" msgid "" "Now install [GNU Mailutils](https://mailutils.org/) (`sudo apt-get install " "mailutils` or the equivalent on your OS), and send yourself your first " "email:" msgstr "" msgid "" "And that's about it, you've got mail. Here are some more places where it " "might be applicable:" msgstr "" msgid "...and so on." msgstr "" msgid "" "You may consider adding a `alias mail='mail -aFrom:email@example.com'` so " "you don't keep re-entering the \"From: \" part." msgstr "" msgid "Send yourself some emails to see it working!" msgstr "" msgid "" "# file /etc/ssmtp/ssmtp.conf\n" "FromLineOverride=YES\n" "MailHub=smtp.gmail.com:587\n" "UseSTARTTLS=YES\n" "UseTLS=YES\n" "rewriteDomain=gmail.com\n" "root=username@gmail.com\n" "AuthUser=username\n" "AuthPass=password\n" msgstr "" msgid "echo body | mail -aFrom:email@example.com email@example.com -s subject\n" msgstr "" msgid "" "# report a backup cronjob, attaching logs\n" "set -e\n" "\n" "finish() {\n" " status=$?\n" " if [[ $status = 0 ]]; then\n" " STATUS=\"SUCCESS (status $status)\"\n" " else\n" " STATUS=\"FAILURE (status $status)\"\n" " fi\n" "\n" " mail user@example.com \\\n" " -s \"Backup job report on $(hostname): ${STATUS}\" \\\n" " --content-type 'text/plain; charset=utf-8' \\\n" " -A\"$LOG_FILE\" <<< 'The log report is in the attachment.'\n" "}\n" "trap finish EXIT\n" "\n" "do-long-backup-cmd-here\n" msgstr "" msgid "" "# share the output of a cmd with someone\n" "some-program | mail someone@example.com -s \"The weird logs that I was talking about\"\n" msgstr ""