Easy delivery with mstmp and GMail
Friday, January 23rd, 2009At the moment, I really don’t feel like setting up a full-fledged MTA such as sendmail, postfix or qmail. I want to take the simple course, basically because I’m lazy. Fortunately, there are a variety of simple SMTP ‘relays’ out there such as ssmtp and esmtp. Some network officianatos may consider this to be re-inventing the wheel, but then again, I’m sure glad that my car doesn’t roll on stone cylinders.
After some consideration, I chose to go with msmtp. I like its flexible configuration, and it’s just the right size for the job (with room to grow). The major thing I was looking for was STARTTLS support. I wasn’t so concerned with the trust files and certificates, I just had a need to support GMail’s minimum requirements. Yes, msmtp gives you that and the whole 9 yards, for when I need them all.
msmtp Configuration for GMail
With a combination of their official configuration example plus a few targeted suggestions from Grey Bearded Geek’s take at ssmtp, I came up with the following:
# Set default values for all following accounts.
defaults
host smtp.gmail.com
port 587
timeout off
protocol smtp
domain localhost
# /usr/bin/msmtp --version
# plain cram-md5 digest-md5 gssapi external login ntlm
auth on
user GMAIL-USER
password GMAIL-PASSWD
tls on
tls_starttls on
# WARNING: When the checks are disabled, TLS/SSL sessions will be vulnerable to man-in-the-middle attacks
tls_certcheck off
logfile /var/log/msmtp.log
###syslog on
# A system wide configuration is optional.
# If it exists, it usually defines a default account.
# This allows msmtp to be used like /usr/sbin/sendmail.
account default
# Construct envelope-from addresses of the form "user@oursite.example".
###auto_from on
from USER@DOMAIN
maildomain DOMAIN
You plop in the GMAIL-USER and GMAIL-PASSWD, and you’re good to go.
Custom From: Address
I soon learned that the from and maildomain settings are irrelevant; Google will not arbitrarily change the From: header of your mail. That makes sense. So the mail will appear as if it’s coming from you, personally. Well, it turns out that there’s a few things you can do to get around that.
- Create yourself a dedicated GMail account. Now you have isolated your soon-to-be-wildly-popular start-up’s e-mail account from your personal one.
- Follow the instructions on adding a custom From: address to your account. I had to use the older version of the GMail interface to do so. Google will verify that you own the address — you’d better be able to receive mail at that address — and then you can make it your default.
GMail will now send your mail as it were coming from that address, but it will do so without providing an alias.
- When sending your outbound mail, you can include the following headers:
From: ALIAS Reply-To: ALIAS <USER@DOMAIN>Google will respect the
ALIASportion of theFrom:address, though not the address itself. TheReply-To:is optional, but respected in its entirety (alias and address).
Works like a charm.
