From 10a15d3eae483f6db54ee836c55fc5f020e8452a Mon Sep 17 00:00:00 2001 From: EuAndreh Date: Sat, 5 Apr 2025 06:45:33 -0300 Subject: Makefile: Add test for internal broken links --- .../tils/2020/09/04/cli-email-fun-profit.adoc | 75 ++++++++++++++++++++++ .../tils/2020/09/04/email-cli-fun-profit.adoc | 75 ---------------------- 2 files changed, 75 insertions(+), 75 deletions(-) create mode 100644 src/content/tils/2020/09/04/cli-email-fun-profit.adoc delete mode 100644 src/content/tils/2020/09/04/email-cli-fun-profit.adoc (limited to 'src/content/tils/2020/09/04') diff --git a/src/content/tils/2020/09/04/cli-email-fun-profit.adoc b/src/content/tils/2020/09/04/cli-email-fun-profit.adoc new file mode 100644 index 0000000..5476fac --- /dev/null +++ b/src/content/tils/2020/09/04/cli-email-fun-profit.adoc @@ -0,0 +1,75 @@ += Send emails using the command line for fun and profit! + +:ssmtp: https://wiki.archlinux.org/index.php/SSMTP +:mailutils: https://mailutils.org/ + +Here are a few reasons why: + +. 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 {ssmpt}[install and configure SSMTP] for using, say, Gmail as the email +server: + +[source,shell] +---- +# file /etc/ssmtp/ssmtp.conf +FromLineOverride=YES +MailHub=smtp.gmail.com:587 +UseSTARTTLS=YES +UseTLS=YES +rewriteDomain=gmail.com +root=username@gmail.com +AuthUser=username +AuthPass=password +---- + +Now install {mailutils}[GNU Mailutils] (`sudo apt-get install mailutils` or the +equivalent on your OS), and send yourself your first email: + +[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 +be applicable: + +[source,shell] +---- +# report a backup cronjob, attaching logs +set -e + +finish() { + status=$? + if [[ $status = 0 ]]; then + STATUS="SUCCESS (status $status)" + else + STATUS="FAILURE (status $status)" + fi + + mail user@example.com \ + -s "Backup job report on $(hostname): ${STATUS}" \ + --content-type 'text/plain; charset=utf-8' \ + -A"$LOG_FILE" <<< 'The log report is in the attachment.' +} +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. + +Send yourself some emails to see it working! 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 deleted file mode 100644 index 5476fac..0000000 --- a/src/content/tils/2020/09/04/email-cli-fun-profit.adoc +++ /dev/null @@ -1,75 +0,0 @@ -= Send emails using the command line for fun and profit! - -:ssmtp: https://wiki.archlinux.org/index.php/SSMTP -:mailutils: https://mailutils.org/ - -Here are a few reasons why: - -. 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 {ssmpt}[install and configure SSMTP] for using, say, Gmail as the email -server: - -[source,shell] ----- -# file /etc/ssmtp/ssmtp.conf -FromLineOverride=YES -MailHub=smtp.gmail.com:587 -UseSTARTTLS=YES -UseTLS=YES -rewriteDomain=gmail.com -root=username@gmail.com -AuthUser=username -AuthPass=password ----- - -Now install {mailutils}[GNU Mailutils] (`sudo apt-get install mailutils` or the -equivalent on your OS), and send yourself your first email: - -[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 -be applicable: - -[source,shell] ----- -# report a backup cronjob, attaching logs -set -e - -finish() { - status=$? - if [[ $status = 0 ]]; then - STATUS="SUCCESS (status $status)" - else - STATUS="FAILURE (status $status)" - fi - - mail user@example.com \ - -s "Backup job report on $(hostname): ${STATUS}" \ - --content-type 'text/plain; charset=utf-8' \ - -A"$LOG_FILE" <<< 'The log report is in the attachment.' -} -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. - -Send yourself some emails to see it working! -- cgit v1.2.3