Recently, I decided to revamp my email setup. I don’t really love email, but it’s such an important method of communication that I needed to get it under control. I’m going to put together a several-post guide explaining my reasoning, technical details, and my new email process.
Other posts in this series (all will be linked here as the posts go up:)
- Part 1: My basic setup
- Part 2: OfflineIMAP
- Part 3: notmuch
- Part 4: alot and khard
- Part 5: msmtp
- Part 6: Wrap-up
Intro
msmtp is the final piece in the puzzle. So far we have:
- OfflineIMAP to fetch mail from an IMAP server
- notmuch to index and tag your email
- alot to read and compose email, and khard for integrating an address book
msmtp is a utility for sending email through an SMTP server. After you compose an email using alot, msmtp will handle sending it out. You’ll want msmtp installed on the machine you are using to compose email – so I have it installed on my two workstations rather than on a centralized server.
(In practice, I have it on the server as well in case I ever need to ssh in and write an email, but I haven’t used that option yet).
Installing msmtp
In Arch Linux, msmtp is in the standard repositories. Install it like so:
sudo pacman -S msmtp
Configuration
I should mention that the Arch Linux wiki is really helpful for just about everything, and msmtp is no exception. They have a great article here.
After installing, copy the example configuration into your home directory and start editing!
cp /usr/share/doc/msmtp/msmtp-user.example ~/.msmtprc
vim ~/.msmtprc
Overall, editing this file is pretty easy – just follow the example. Your SMTP server may require some specific settings, so play with it a bit. See some testing tips in the next section of this post.
Here’s an example of one of my accounts, with some sensitive information edited:
account ajy
host smtp.example.com
port 587 # Alternatively, try port 465 if this one doesn't work
from aaron@example.com
user aaron@example.com
# tls and password - you should decide how you will handle these
For the TLS certificate and password settings, follow the examples in the config file based on what strategy you will use.
Set a default account:
account default : ajy # Choose an account name as specified above
Testing your configuration
To test your SMTP configuration, I recommend creating an email in a text file: vim test-mail.txt
with something like the following content:
To: username@domain.com
From: username@gmail.com
Subject: A test
Hello there.
Use real To and From emails so you can confirm the mail actually goes through.
Then, run this command:
cat test-mail.txt | msmtp -a account-name
The -a
flag specifies which account will be used. Replace account-name
with the name of an account from your .msmtprc file.
Integrating with alot
In practice, you won’t have to deal directly with msmtp. Instead, the send
command in alot should invoke msmtp automatically.
To set this up, see the previous post in this series (linked at top). The example alot configuration I supplied includes configuration for msmtp on a per-account basis.
Next
A final wrap-up!