7

I have set up MSMTP with the following but if I send an e-mail from the CLI it either gets blocked, or ends up in my SPAM because it has no TO/FROM or anything up top. But e-mails from CRON are properly formatted.

sudo apt-get update
sudo apt-get install -y msmtp msmtp-mta 

# MSMTPRC Configuration
cat << EOL >/etc/msmtprc
# Set default values for all following accounts.
defaults
auth           on
tls            on
tls_trust_file /etc/ssl/certs/ca-certificates.crt
logfile        /var/log/msmtp.log
aliases        /etc/aliases

# Comcast
account        Comcast
host           smtp.hmc1.comcast.net
port           587
from           USER@COMCAST
user           USER@COMCAST
password       PWD


account default : Comcast
EOL

# Set Strong Permissions due to Plain Text PWD
sudo chmod 600 /etc/msmtprc

# Configure User Alias
cat << EOL >/etc/aliases
# Example aliases file  
# Send root to Joe and Jane
#root: [email protected], [email protected]
# Send everything else to admin
#default: [email protected]
# Send cron to Mark
#cron: [email protected]
#############################
root : [email protected]
EOL

# Needed for Mail Command
cat << EOL >/tmp/testfile
To: [email protected]
From: [email protected]
Subject: E-Mail Setup Script has Completed Successfully

"${HOSTNAME} Has been configued to use msmtp, this program will e-mail all CRON results automatically, but does not suporrt the "mail -s" command
EOL

enter image description here

1 Answer 1

6

Unfortunately, msmtp does nothing to help you with the To: field that mail clients display. It only uses the addresses you provide to communicate with the mail server -- for whatever reason, it does nothing to include those addresses within the message body.

This behavior is different from its handling of the From: and Date: fields, which will be automatically included by default (read more).

You can see this directly by running in verbose mode (look for lines after "--> 354 Go ahead ..."):

Generally, mail servers will happily accept such messages -- and many will also happily deliver them -- but certain companies with unsophisticated technology will wrongly flag all such messages as spam. In that situation, your only recourse may be to include a To: field in the message piped to msmtp. (It may not even need to be a valid To: email address.)

2
  • Or... Just figure out Postfix and get it setup correctly. I finally took the dive and configured a central postfix server which performs as I want and then setup all my machines to use it as a SMTP Relay Host. +1 for me tho, thanks for looking into this. Oct 23, 2019 at 23:23
  • I use postfix on other servers, but msmtp has its place too :) Oct 25, 2019 at 18:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .