Configuring Your Linux Server for Email Notifications
It's common to run a Linux server that needs to send email from time to time. This might be a requirement of a web application (e.g. for password management), and/or the system itself might send email to its root account if some process reports an error (automated hard disk monitoring with Smartmontools is a valuable example of this).
You can install a fully featured mail transport agent (MTA) like Postfix for that, but this is a complex task that's made more complex in the face of barricades put up by other mail servers to fight spam. It makes more sense to install a very simple agent that in turn hands off the final delivery task to a professionally maintained MTA such as the one provided by your internet service provider (ISP).
Your ISP's MTA is a good choice for this because you are their customer and they expect to manage mail on your behalf. You could instead use something like Google Mail for that, but it will generally present more obstacles because it's open to the public.
Here I will show an example where your ISP is Comcast. On the server we will install SSMTP and Mailx for mail transport. SSMTP is a simple MTA proxy and Mailx is a simple Mail User Agent (MUA). To install these on an Ubuntu or Debian server, do this:
sudo apt-get install ssmtp sudo apt-get install bsd-mailx
Be sure to install ssmtp first, otherwise bsd-mailx will bring in postfix as its default MTA.
Next, make sure you have your email login ID and password for your Comcast email account. These are needed because Comcast will require authentication before forwarding email to ensure you are not a random spammer.
Then edit the file /etc/ssmtp/ssmtp.conf so that it looks something like this:
root=YourNormalEmailAddress mailhub=smtp.comcast.net:587 UseSTARTTLS=YES UseTLS=YES AuthUser=YourComcastLogin AuthPass=YourComcastPassword rewritedomain=SomeDomainName.com hostname=AnyHostName FromLineOverride=YES
Substitute YourNormalEmailAddress, YourComcastLogin, YourComcastPassword, SomeDomainName.com and AnyHostName as appropriate. SomeDomainName.com might be any valid domain, or perhaps comcast.net. If the login name is an email address then it probably ends with "@comcast.net". YourNormalEmailAddress is whatever email address you want system notifications to go to, for example email@example.com; it is commonly not your ISP email.
You can leave the existing commented-out lines in there as helpful documentation.
Then you can test email sending to your normal email account with a command like this:
echo test | mail -v -s "testing ssmtp setup" root
Or you can use a full email address like "firstname.lastname@example.org" instead of "root".
Make sure the command completes without errors, and that you receive the email. It may be in your Spam folder.