It’s useful to be able to send email from a Linux webserver. I do it to get MediaWiki page change notifications and other automated status updates. I wanted something that supported two-factor authentication, and this does.
This guide is for you, if:
- You don’t want to run a mail server
- You want to send email, and you don’t care about receiving it
- You want people to receive the emails that your server sends
I’ve used this method with Linode, and it works perfectly.
Install mailutils
~ sudo apt-get install mailutils
When the setup wizard launches, choose the unconfigured option. You don’t need to do any special configuration to get this to work.
Install and configure sstmp
~ sudo apt-get install ssmtp
~ sudo vim /etc/ssmtp/ssmtp.conf
- Hit “i” to enter Insert mode.
- Uncomment
FromLineOverride=YES
by deleting the#
- Add the following to the file:
AuthUser=<user>@gmail.com
AuthPass=Your-Gmail-Password
mailhub=smtp.gmail.com:587
UseSTARTTLS=YES
- Save and close the file:
- Hit Escape
- Type
:wq
- Hit Enter
If you’re using two-factor authentication
Create a new application-specific password to use in the config file above. (If you’re using Gmail, you can manage those passwords here.)
Test it out
~ echo "This is a test" | mail -s "Test" <user>@<email>.com
Using a webmail service other than Gmail
You can follow the same pattern that I used above. You’ll need to:
- Subsitute the SMTP address and port for your email service (e.g. Yahoo!) where it says
smtp.gmail.com:587
. (587 is the port number.) - Set up an application-specific password if your webmail provider allows it, and paste that into the password line, the way I did with Gmail. (Yahoo! appears to have something similar.)