Moar e-mail notifications

Recap

So, last time I was able to configure an e-mail notification for the router logins, using my iCloud e-mail and Apple’s SMTP server. This gave me a boost to play around with other equipment and services I have.

Next victim: my Ubuntu VM

I wanted to keep an eye on my Ubuntu docker VM so it was the next logical subject for this experiment. I needed a local SMTP server which is able to use Apple’s SMTP, since I still don’t have the urge to host my own. As a quick solution, Postfix came to mind first, since I’m most familiar with that, but hey - how would a guy learn anything new if he stayed in his little bubble. So, finally I decided on sSMTP.

Installation

Yup, guessed right, just apt install it:

sudo apt install ssmtp

Configuration

Configuring sSMTP is really straightforward, I’ll just dump here the config files.

/etc/ssmtp/ssmtp.conf

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
# The user that gets all the mails (UID < 1000, usually the admin)
root=my-icloud@email.address

# The mail server (where the mail is sent to), both port 465 or 587 should be acceptable. In this instance it’s Apple’s SMTP server.
mailhub=smtp.mail.me.com:587

# The full hostname. Must be correctly formed.
hostname=my.vm.lan

# When using port 587, change UseSTARTTLS=Yes
UseSTARTTLS=Yes

# Username/Password
AuthUser=my-icloud@email.address
AuthPass=iCloud-app—password
AuthMethod=LOGIN

# E-mail 'From header's can override the default domain?
FromLineOverride=yes

/etc/ssmtp/revaliases

Put an alias in this file so the root user (which will send all of my e-mails) will be mapped to my iCloud e-mail address. Honestly, don’t know if it’s needed but what the hell…

1
2
3
4
5
6
7
8
# sSMTP aliases
#
# Format:       local_account:outgoing_address:mailhub
#
# Example: root:your_login@your.domain:mailhub.your.domain[:port]
# where [:port] is an optional port number that defaults to 25.

root:icloud@email.address:smtp.mail.me.com:587

Testing

You can test the config with a simple one-liner:

echo -e 'Subject: test\n\nTesting ssmtp' | sendmail -v icloud@email.address

Conclusion

After testing it, I went ahead and used this config to receive an e-mail each time the unattended-upgrade cronjob ran. Which reminds me, that could be our next topic.

On the whole, the process was really easy, so I guess it’s time to break something if I want to learn something. Oh, well… Did I mention my shiny, new server died on me? We will have something to talk about next time.