You have a script and you want to send an email, or worse, someone else
has a program and they are sending an email. Many programs expect something
sendmail compatible to available on your system, e.g. cron scripts.
Rather than install a mail transfer agent and/or mail delivery agent and/or mail user agent, and god knows what other pieces that make up a proper mailbox, we can install something that just sends emails.
$ sudo pacman -S msmtp msmtp-mta
msmtp is the small program that does the sending and
sendmail compatibility at
/usr/bin/sendmail. The program requires a working
internet connection as it cannot queue emails. That’s how simple it is.
We can use a 3rd party SMTP server such as SendGrid or Gmail with the
defaults aliases /etc/aliases port 587 tls on tls_trust_file /etc/ssl/certs/ca-certificates.crt syslog on account sendgrid host smtp.sendgrid.net auth on user apikey password ACTUALAPIKEYHERE auto_from on maildomain em.example.com account default : sendgrid
There are a few tweaks to including enabling logging, automatically setting
a FROM email that is
email@example.com, using the SendGrid account to send
emails by default if one is not otherwise specified, and finally setting up some
We’ll set up a default alias in
Add yourself to mail:
gpasswd -a <YOU> mail (check with
We can test it with (the
default alias will be mapped to the real recipient
email address defined earlier):
$ printf "Subject: Hello World\n\Or rather just me.\n" | msmtp default
mail default works as an alternative.
- We are using the
~/.msmtprcif we need to isolate sending accounts from other users/applications.
- We just
echodoesn’t seem to new-line properly.
- We set the subject, but we should also set
- Not sure how to get it to work with SendGrid’s domain white-listing, but it doesn’t really matter if you’re just emailing yourself.
The Arch Linux Wiki has more details!