HOWTO Send an email using Gmail from a system configuration using msmtp and heirloom-mailx (Ubuntu)

Introduction and Scope

The following procedure describes the steps to follow to create a solution what will send out an email. This was verified on Ubuntu (both server and GUI platforms). The setting will be stored as a system configuration rather than a user configuration (in which each user have their specific settings).

Installing the packages

Open a terminal session and update the package index

Configuring the solution

Since this is a system configuration the placement of the files will be in the /etc/ directory.

The Google username and password

The from and user parameters in the file /etc/msmtprc are those you use to log into your Gmail.

  • You can block it by revoking that password If the app password is compromised and is being used to send emails from your account;
  • It allows you to monitor the last time a device/service sent out an alert;
  • If you change your Google password, app passwords are not impacted;
  • The app password is limited to only email transmissions. You cannot use it to log into your Google account.
  1. Click “Security”
  2. Scroll to the “Signing in to Google” section
  3. Click on “App passwords”
  4. From the “Select app” menu choose “Other (Custom name)”
  5. Enter a descriptive name to identify the service. I have a Google account specifically for machine-2-human communications. Every computer, server, UPS, security camera and IOT device that I have set up to send me an alerts or state information via email use this account.
  6. Click the Generate button and copy the app password and paste it in the /etc/msmtp configuration file. Save the file and exit the editor.

Granting ownership and access rights

If you type ‘groups msmstp’ you are informed that msmtp is a member of the group msmtp.

Testing the solution

Open a terminal window and type in the following. Replace <recipient account> with your email account.

Proof of concept

My use case is to have the computer email me whenever it starts. This event should happen before any user has logged in.

30+ years' experience in the field of IT in the Financial (Insurance / Banking), Services and Education industries.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store