Setting up msmtp


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


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:

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


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:
To participate in a public discussion, use my public inbox: ~witcher/
Please review the mail etiquette.

Posted on: May 21, 2020

Articles from blogs I read

vdirsyncer status update, May 2023

So far, libdav seems to be working pretty solid for interacting with CalDav server, and davcli has been handy for interactively inspecting remote collections. There are a few reported issues for the previous vdirsyncer implementation that are related URL d…

via Hugo Barrera's site May 27, 2023

Status update, May 2023

Hi all! This status update comes in a bit late because I was on leave last week. The highlight this month is the HDR hackfest, I’ve written a dedicated blog post about it. After the publication of that blog post, I’ve sent out an RFC to dri-devel. We’ve made s…

via emersion May 22, 2023


It kind of crept up on me. One day, sitting at my workstation, I stopped typing, stared blankly at the screen for a few seconds, and a switch flipped in my head. On the night of New Year’s Eve, my backpack was stolen from me on the train from Berlin to Amste…

via Drew DeVault's blog May 1, 2023

Generated by openring