Hi, 


While working with VESTA I realized that It is difficult to manage Email, DNS and DATABASE service on a single server, due to the following reason :


  1. When we fix one service it affects another.
  2. We can not use any standby during debugging and fixing the problem.
  3. Backup Restore will vanish database.
  4. In case of email server blacklisting it will blacklist our file server also.
  5. many more.


I finally decided to saparate Databse, Email and File server from each other and it gave me ease of managing the services.


For Email, I used msmtp which is basically a route diverter



-- Copy of blog contains installation and utility.


Configure msmtp to use Mailgun or Sendgrid

   Published •            2 min read     

I had a few VMs configured with ssmtp to relay a small number of emails, usually from cron jobs. Unfortunately, this project is no longer maintained so it’s unfit for production, and while Postfix is a solid piece of software, I was looking for something very lightweigth.

I came across msmtp, which fit the bill perfectly and is trivial to set up.

On a Debian based distro :

apt install msmtp msmtp-mta

Then create /etc/msmtprc to configure it globally on your host. You’ll need to edit the values in caps with your SMTP credentials :

defaults
tls on
tls_trust_file /etc/ssl/certs/ca-certificates.crt
logfile /var/log/msmtp.log

account mailgun
host smtp.mailgun.org
port 587
auth on
user YOUR@MAILGUN_USER.TLD
password YOUR_PASSWORD
from FROM@YOURDOMAIN.TLD

account default : mailgun

You should definitely keep logging enabled. There’s a wealth of information that will come handy.

Using a service like Mailgun, rather than your own SMTP server, ensures better delivery of your email, along with detailed logs and sending stats. If these emails are somewhat critical to you, you may want to set up a secondary provider such a Sendgrid so that you can failover easily, albeit manually – if you need this to be automated because they are mission critical, that’s a job for Postfix.

Simply create another account section. Instead of SMTP credentials, you’ll have to create an API key with sending permissions. Again, edit accordingly :

account sendgrid
host smtp.sendgrid.net
port 587
auth on
user apikey
password YOUR_API_KEY
from FROM@YOURDOMAIN.TLD

Note that user should be apikey.

If you need specific user configurations, you can create ~/.msmtprc files. To route emails to different recipients, you can set up aliases.

Also, you can customize the timeout per account using e.g. timeout 60 to wait one minute.

Finally, send a test email from the command line :

echo "Subject: Testing msmtp" | sendmail -v your@email.tld

If everything went well, you should see your test within a few seconds.