How to configure MSMTP for self-hosted email
š Published: ⢠Thomas Queste
I recently reinstalled my server and configured msmtp to send emails to myself. It wasnāt working right at first. Hereās how to configure it properly.
TL;DR
- Set
allow_from_overridetooff - Use an
aliasesfile with adefaultalias
MSMTP
MSMTP is the recommended tool to send emails from a server, much simpler than a full email solution like Postfix. Itās also actively maintained, unlike SSMTP which I used before.
Install MSMTP with its -mta version:
apt install msmtp-mta
I use the service of MailJet to send emails. Itās free for a few thousand emails per month. Working great for years!
Goal
- Allow services to send email to myself and only myself.
- Ensure MailJet accepts emails only if they originate from myself.
The From field must be set to me. And a default must be set.
Those were the main issues I had.
Configuration
The main points:
- Set
allow_from_overridetooffso that msmtp can set theFromfield - Set a
Fromin MSMTP - AND set an alias file (see below)
Config in /etc/msmtprc:
account default
host in-v3.mailjet.com
port 587
tls on
tls_starttls on
auth on
user 1234
password abcd
from tom@tomsquest.com
allow_from_override off
set_from_header on
aliases /etc/msmtprc_aliases
syslog LOG_MAIL
Aliases in /etc/msmtprc_aliases:
default: tom@tomsquest.com
This way, all conditions are handled:
- a service can set a
Fromfield (root,@tomā¦) - Or no
Fromfield at all
About self-hosting
I self-host most of my services, such as:
- Calendar/Tasks using my custom Radicale image
- qBittorrent
- SearchX
- Backup with Restic
- Synchronization with Syncthing
Self-hosting is an excellent way to learn
Thereās always a risk when you colocate your data with services made by others.
Thatās why I read a lot on Docker and created my own Docker image for the calendar server Radicale! I wanted it to not run as root, be read-only, and avoid pid1 issues.
Requires a Bit of Surveillance
For instance, I receive backup emails twice a day and check each time which files were backed up. Thatās part of my routine.
I also monitor Crowdsec and update emails.
Cumbersome every few years
Yes, upgrades run automatically, but moving from one LTS version to another requires reinstalling. Iāve done it twice in 8 years. No, I didnāt go the Ansible route (it requires testing and thus time), and the same with NixOS. I just have partial documentation of high-level actions and back up my /etc files.