>_
Sending email: ssmtp
Over the years Ive always thought paying for sending emails was too much. Any projects I thought about always involved sending emails, whether for user password resets or notifications.
But the majority of projects I have in my head to work on at the moment mainly involve self hosting and personal notifications. Meaning it would most likely be easier to just send emails to yourself.
So, to get rid of some of my own incorrect beliefs, Im going to go through how to setup email on a Linux machine and prove it can be sent to yourself without issue.
For this I will use ssmtp, this can be installed on a Ubuntu/Debian machine like so:
sudo apt install ssmtp
After this, its a simple case of editing this file as root:
/etc/ssmtp/ssmtp.conf
And look to add something similar to these settings:
root=[Email here]
mailhub=smtp.gmail.com:465
AuthUser=[Email here]
AuthPass=[App password here]
UseTLS=YES
Fill in the blanks there, but you could either choose to create a new email address for this or your own. I use gmail as its free of course. With Gmail your probably best to use App Passwords for this, see here on how to set them up:
https://support.google.com/accounts/answer/185833?hl=en
Essentially its a single use password. After you have those settings saved, something as simple as this:
echo "Subject: Hello" | ssmtp [Email here]
Should send you a new email. In my case Im using my email address as the sender in the settings and then sending to my own email address, so it comes straight through to my inbox.
You can of course pipe a file with something like this:
cat mymail | ssmtp [Email here]
With the contents being something like this:
Subject: Hello World
-blank line-
Message body here, hello there.
I thought I would find the email in my Junk folder, but it came straight through. Even if you dont use ssmtp for this, I think the settings and use of App Passwords would be useful.
This couldnt be used for bulk emails, as for instance I have no proof that it wont just go to the Junk mail of another inbox. I also have no real intention of testing that, as I really just wanted to prove that sending email was very simple for personal notifications. So this should come in handy for some of my future projects.
Because obviously I didnt set this up by reading the docs, here is what I used to help me:
https://unix.stackexchange.com/questions/202934/how-to-send-mail-to-gmail-account-using-ssmtp
16 Jan 2023, 12:19 p.m.
Home