Sending email on system powerup and shutdown

This is a WIP - Shutdown emails aren't being dispatched correctly.

While working from home I sometimes find myself logging into my remote workspace to be greeted with the KDEhttps://kde.org/ logo splash-screen. I found that it would be nice and geeky if I got an email whenever my workstation shuts down and powers up. Let's jump straight into it.

Installing packages

Let's go ahead and install postfix and mutt

Tweak postfix's configuration

Fire up /etc/postfix/main.cf on your favourite editor and set something similar to:

You can use postfix to check your configuration validity

Go ahead and start/enable the postfix service.

Sending emails on power events

Create the script (for instance at /scripts/) that will receive the power event, for instance name it on_power_event.sh

Set the correct permissions

Create the systemd services, for the power off hook lets name it on_power_off.service and set the contents to:

For the power on script, on_power_on.service, write:

Finally, set the service file permissions, copy over files, and enable services:

As mentioned above I still have issues with the shutdown script, if you have anny suggestions leave a comment (WIP). Also I don't remember where I saw the original scripts on stackoverflow so I am missing a reference.

References:

  • https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-postfix-as-a-send-only-smtp-server-on-ubuntu-16-04