HOWTO secure the msmtp configuration using libsecret’s password manager with Microsoft SMTP (Ubuntu)
Introduction and catchup
This is an evolution of “HOWTO Send an email using Gmail from a system configuration using msmtp and heirloom-mailx (Ubuntu)” that you can find here.
Libsecret’s secret-tool utility
The password manager package that is being used here is called secret-tool and is part of the libsecret tools package. Documentation on this tool is available from http://manpages.ubuntu.com/manpages/focal/man1/secret-tool.1.html.
To save a password:
secret-tool store — label=msmtp host smtp.gmail.com
(when prompted type in app generated password)
To verify that the password has been entered correctly:
secret-tool lookup host smtp.gmail.com
Modify the /etc/msmtprc config file:
sudo nano /etc/msmtprc
replace password line with
passwordeval “secret-tool lookup host smtp.gmail.com”
To use Microsoft rather than Google
Check the Sync option in your outlook client for the SMTP settings. The port and server name are retrieved from here.
An app password needs to be generated from within Microsoft and stored in the secret-tool vault.
/etc/msmtprc needs to be modified to cater for Microsoft’s SMTP server.
password “secret-tool lookup host smtp.office365.com”
# Syslog logging with facility LOG_MAIL instead of the default LOG_USER
To test from the terminal that the email is working type the following
echo “Hello, World! (Outlook)” | mail -s “HOWTO #2a” <recipient account>