diff options
Diffstat (limited to 'src/content/tils/2020/09/04')
-rw-r--r-- | src/content/tils/2020/09/04/email-cli-fun-profit.adoc | 51 |
1 files changed, 23 insertions, 28 deletions
diff --git a/src/content/tils/2020/09/04/email-cli-fun-profit.adoc b/src/content/tils/2020/09/04/email-cli-fun-profit.adoc index 320f3ab..5476fac 100644 --- a/src/content/tils/2020/09/04/email-cli-fun-profit.adoc +++ b/src/content/tils/2020/09/04/email-cli-fun-profit.adoc @@ -1,25 +1,22 @@ ---- -title: Send emails using the command line for fun and profit! -date: 2020-09-04 -layout: post -lang: en -ref: send-emails-using-the-command-line-for-fun-and-profit ---- -Here are a few reasons why: += Send emails using the command line for fun and profit! -1. send yourself and other people notification of cronjobs, scripts runs, CI - jobs, *etc.* +:ssmtp: https://wiki.archlinux.org/index.php/SSMTP +:mailutils: https://mailutils.org/ -2. leverage the POSIX pipe `|`, and pipe emails away! +Here are a few reasons why: -3. because you can. +. send yourself and other people notification of cronjobs, scripts runs, CI + jobs, _etc._ +. leverage the POSIX pipe `|`, and pipe emails away! +. because you can. Reason 3 is the fun part, reasons 1 and 2 are the profit part. -First [install and configure SSMTP][ssmtp] for using, say, Gmail as the email +First {ssmpt}[install and configure SSMTP] for using, say, Gmail as the email server: -```shell +[source,shell] +---- # file /etc/ssmtp/ssmtp.conf FromLineOverride=YES MailHub=smtp.gmail.com:587 @@ -29,19 +26,21 @@ rewriteDomain=gmail.com root=username@gmail.com AuthUser=username AuthPass=password -``` +---- -Now install [GNU Mailutils][gnu-mailutils] (`sudo apt-get install mailutils` or the +Now install {mailutils}[GNU Mailutils] (`sudo apt-get install mailutils` or the equivalent on your OS), and send yourself your first email: -```shell +[source,shell] +---- echo body | mail -aFrom:email@example.com email@example.com -s subject -``` +---- -And that's about it, you've got mail. Here are some more places where it might +And that's about it, you've got mail. Here are some more places where it might be applicable: -```shell +[source,shell] +---- # report a backup cronjob, attaching logs set -e @@ -61,20 +60,16 @@ finish() { trap finish EXIT do-long-backup-cmd-here -``` +---- -``` +.... # share the output of a cmd with someone some-program | mail someone@example.com -s "The weird logs that I was talking about" -``` +.... ...and so on. You may consider adding a `alias mail='mail -aFrom:email@example.com'` so you -don't keep re-entering the "From: " part. +don't keep re-entering the ``From:'' part. Send yourself some emails to see it working! - -[ssmtp]: https://wiki.archlinux.org/index.php/SSMTP -[gnu-mailutils]: https://mailutils.org/ -[forwarding-wiki-section]: https://wiki.archlinux.org/index.php/SSMTP#Forward_to_a_Gmail_mail_server |