Setting up msmtp

msmtp

msmtp is a commandline smtp client that reads the message body from stdin.

configuration

You need to first install msmtp with the package manager of your choice.
After installing, create a confi file. msmtp looks for those in $XDG_CONFIG_HOME/msmtp. The config file simply needs to be called config.
Here’s a sample configuration file which you can edit:

defaults
auth on
tls on
tls_trust_file /etc/ssl/certs/ca-certificates.crt
logfile /home/{user}/.config/msmtp/msmtp.log

account {account1}
host {smtp hostname}
port 465
from {from field}
user {smtp username}
passwordeval "gpg --quiet --for-your-eyes-only --no-tty --decrypt $XDG_CONFIG_HOME/msmtp/.msmtp-{account1}.gpg"
# only if your smtp server doesnt support STARTTLS
#tls_starttls off

# vim:filetype=msmtp

The last line exists to make vim highlight the configuration file with the right syntax. Feel free to remove it if you want.
Make sure you replace all your occurances of:

  • {user} - the username you are logged in to on your computer
  • {account1} - a string you have to reference later to select that profile
  • {smtp hostname} - the hostname of your smtp server
  • {smtp username} - the username you log in with on the given smtp server

usage

Using msmtp is very simple. Supply the body of the message via stdin, set a subject via the -s flag, set the account to use via the -a flag and send it to the email supplied at the very end.

Do you have a comment on one of my posts? Feel free to send me an E-Mail: witcher@wiredspace.de
To participate in a public discussion, use my public inbox: ~witcher/public-inbox@lists.sr.ht (Archive)
Please review the mail etiquette.

Posted on: May 21, 2020

Articles from blogs I read

WPA3 support for OpenBSD 802.11 wireless funded by NLNet Foundation

The project to implement WPA3 support for OpenBSD 802.11 wireless has now been funded by a grant from the NLNet Foundation. The work is to be carried out by Stefan Sperling (stsp@) and Chirpy Software. The announcement states, This project delivers the second …

via OpenBSD Journal October 17, 2025

docs.rs: changed default targets

Changes to default build targets on docs.rs This post announces two changes to the list of default targets used to build documentation on docs.rs. Crate authors can specify a custom list of targets using docs.rs metadata in Cargo.toml. If this metadata is not …

via Rust Blog October 16, 2025

Status update, October 2025

Hi! I skipped last month’s status update because I hadn’t collected a lot of interesting updates and I’ve dedicated my time to writing an announcement for the first vali release. Earlier this month, I’ve taken the train to Vienna to attend XDC 2025. The confer…

via emersion October 16, 2025

Generated by openring