HOWTO secure the msmtp configuration using libsecret’s password manager with Microsoft SMTP (Ubuntu)

Alan C. Bonnici
2 min readNov 23, 2020

--

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.

account default
auth on
tls on
tls_trust_file /etc/ssl/certs/ca-certificates.crt
logfile /var/log/msmtp

# outlook
host smtp.office365.com
port 587
from <account>@outlook.com
user <account>
password “secret-tool lookup host smtp.office365.com”

# Syslog logging with facility LOG_MAIL instead of the default LOG_USER
syslog LOG_MAIL

To test from the terminal that the email is working type the following

echo “Hello, World! (Outlook)” | mail -s “HOWTO #2a” <recipient account>

--

--

Alan C. Bonnici
Alan C. Bonnici

Written by Alan C. Bonnici

30+ years' experience in the field of IT and Tech, Services and Education industries.

No responses yet