Sending Email to Self with Swaks

Email is one of those protocols that still works. It reaches me where I am. It also has various clients and libraries that work reasonably well. And it can carry almost any kind of content (Of course, there are limitations attachment size and type, etc). I use it every day, including emailing to myself.

I don't think I am the first to send emails to myself, primarily automated emails. Most emails I receive from myself are reminders, reports, alerts, and calendar invites. I have an account specially made to send these automated emails. 

I am always in search of good tools to send emails. Recently I found Swaks (Swiss Army Knife for SMTP), a command-line tool.

Swaks is a featureful, flexible, scriptable, transaction-oriented SMTP test tool written and maintained by John Jetmore. It is free to use and licensed under the GNU GPLv2.


I have setup the following environment variables 

export SWAKS_OPT_from=
export SWAKS_OPT_h_From=
export SWAKS_OPT_server=
export SWAKS_OPT_port=
export SWAKS_OPT_auth_user=
export SWAKS_OPT_auth_password=
export SWAKS_OPT_auth=LOGIN

Mostly because I don't want to pass these values every time I invoke swaks.  

An example usage, I have a script that sends me a calendar event about my next blood donation. I trigger this shell script on the day I donate blood. It logs the event into a tracker. Then it creates an ICS file for the next donation day (90 days) and sends me an email about it. Emailing part of it is handled by swaks. And it looks like this.

swaks --tls --to --body "Next Blood Donation" --header "Subject: [TBot] Next Blood Donation" --attach ./donation.ics

I could have used Google Calendar APIs. But this works across the systems and with all kinds of calendar apps. And very easy to do as well.

Swaks also alerts me on important job completion. Sending me console output along with the alert. Why not any other push notifications? you might ask. I do use pushover for some of the things.

But nothing like an email; given how many tools exist to process the emails and how much attention I pay to emails, there is no alternative. Added benefits like its easy to share with others, can be tagged, archived, and searched later, and is known to everyone.

Swaks is the most accessible email sending CLI tool that I have found. So it gets used every day for something or the other.

You can read this blog using RSS Feed. But if you are the person who loves getting emails, then you can join my readers by signing up.

Join 2,240 other subscribers

1 Response

  1. December 8, 2021

    […] example, I can render the email.html template using the data from data.json and pipe it to swaks to email […]