brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: msmtp passwordeval keeps the SMTP password out of ~/.msmtprc

Linux
~/tips/tip-msmtp-passwordeval-pretend

passwordeval gpg2 --no-tty -q -d ~/.msmtp-password.gpg

Fetches the SMTP password from a command, so no plain password sits in the config.

A mail setup for server alerts always ends up needing a password somewhere. The default place, a plain line in a config file, is the one the msmtp manual itself calls not a good idea. The alternative takes one line.

passwordeval gpg2 --no-tty -q -d ~/.msmtp-password.gpg

Put that in the account section of ~/.msmtprc, next to auth on and user. The manual says msmtp uses the output of the command on standard output as the password. The example comes from the manual and decrypts a GnuPG file, but any command that prints the password works, such as a keyring query.

The manual recommends two ways to store the password: the system key ring, or an encrypted file together with passwordeval. The key ring route for Gnome uses secret-tool and for macOS the Keychain. If you do put a password in the config with password, the manual says to make sure only you can read the file.

Two details from the documentation. The command must not touch standard input, and if in doubt you should append < /dev/null. And you can check what msmtp will use without sending anything:

msmtp --pretend --account=alerts

-P (--pretend) prints the configuration settings that would be used and does nothing else. The manual says an asterisk is printed instead of the password.

The caveat is the unattended case. In the manual’s example gpg-agent asks for the decryption password once, which doesn’t suit an alert script that runs when nobody is at the keyboard. Pick the key ring or another command that can answer without a prompt for those. This follows the manual and was not run, because msmtp was not installed here.

Further reading: msmtp manual

More Linux tips notify-send -r "$id" "Backup" "Done" pgrep -af 'sleep 301' smbstatus -L msmtp --serverinfo --tls --tls-certcheck=off --host=smtp.example.com --port=587 smbclient //server/share -U user -Tc backup.tar "*" All Linux tips (283) All topics

Link