[root tip] [How To] Setup MTA on Manjaro Linux using Proton Mail

As a consequence of the spam plague - almost every provider of consumer internet block outgoing traffic on port 25.

This provides an obstacle for those wanting to send automated mail as part of local service monitoring and it is not as simple as the solution posted in this topic.

Often your email provider will allow SMTP submission using your email account.

Manjaro MTA

A practical implementation of Msmtp - Arch Wiki

I remember an old topic where a user wanted to send mail using a bash script.

My usecase was a little different - I need to have an alert when a raid member - monitored by mdmonitor.service - fails

Setting this up was fairly easy using msmtp.

install msmtp

First install the msmtp and msmtp-mta package

pacman -S msmtp msmtp-mta

msmtp-mta provides an alias to sendmail which is convenient if you are familiar with sendmail syntax.

Requirement

You will need an external mail account providing SMTP submission e.g. a Proton Mail Essentials account but any account providing SMTP submission will do.

The steps to create SMTP token (app password) for a Proton Mail account:

  • Login to your proton account
  • Click the gear icon in upper right corner
  • Click All Settings
  • In the Proton Mail section
  • Click IMAP/SMTP
  • Scroll down to SMTP Submission
  • Click Generate token

When you have generated the token, write down the displayed information

  • SMTP username
  • SMTP token
  • SMTP server
  • SMTP port

User configuration

Create the file ~/.msmtprc

# Set default values for all following accounts.
defaults
auth           on
tls            on
tls_trust_file /etc/ssl/certs/ca-certificates.crt
logfile        ~/.msmtp.log

# Proton mail
account        protonmail
host           smtp.protonmail.ch
port           587
tls_starttls   on
from           <SMTP username>
user           <SMTP username>
password       <SMTP token>

# Set a default account
account default: protonmail

Make the file private

chmod 600 ~/.msmtprc

Validating configuration

First test your configuration

sendmail --serverinfo

Then send a test mail

printf "Subject: Test\n\nhello there username." | msmtp -a default someone@somedomain.example

See → Test functionality - Msmtp - Arch Wiki for other tips

Using mail command

Create the personal mail spool storage

touch /var/spool/mail/<yourusername>
mail -s "THIS is A TEST" someone@somedomain.example

Type in the message body and terminate using CtrlD then yEnter

See man mail for information

OPTIONAL headless server

It is optional to allow the system to send mail on system events - e.g. mdmonitor.service alerting when a raid member fails.

/etc/msmtprc

# A system wide configuration file is optional.
# If it exists, it usually defines a default account.
# This allows msmtp to be used like /usr/sbin/sendmail.
account default

# The SMTP smarthost
host            smtp.protonmail.ch
port            587
tls             on
tls_starttls    on

# Construct envelope-from addresses of the form "user@oursite.example"
#from %U@oursite.example
# Do not allow programs to override this envelope-from address via -f
#allow_from_override off
allow_from_override on
# Always set a From header that matches the envelope-from address
set_from_header on

# Syslog logging with facility LOG_MAIL instead of the default LOG_USER
syslog LOG_MAIL

host            smtp.protonmail.ch
auth            on
user            <SMTP username>
password        <SMTP TOKEN>
from            <SMTP username>