Last year when I originally moved the Wishingline site and a handful of others over a shiny new slice at Slicehst one of the issues I ran into was handling outgoing mail from contact forms, Movable Type, etc. I’m no server admin and despite knowing enough to be dangerous, setting up a secure mail server that can handle multiple domains was definitely outside my comfort zone.
Thanks to Ethan, I discovered a gem of an open source project called MSMTP which was just what I needed; the exception being that I couldn’t figure out how to use it with multiple domains. Until last week that is.
Of course it’s really easy.
Installing and Configuring for Multiple Domains
MSMTP provides two ways you can configure the software using a simple and well-documented configuration file format. It’s all plain text so it’s easy to create, edit and back up.
Installing the Software
Installing MSMSTP requires the following packages which can be installed using the
aptitude tool on Ubuntu. Installation on other *nixes may vary.
$ aptitude install msmtp msmtp-mta ca-certificates
Once you have everything installed, you need to create a configuration file either in
/etc/msmtprc or by creating a user-specific one in your user’s home directory. If you need mail services for more than one domain, I suggest using the global configuration option.
I’m going to assume you’re reasonably comfortable working in a Unix environment from here on out though if you know what you’re doing you can do all of this just as easily using ExpanDrive and TextMate without having to touch the Terminal.
$ sudo nano /etc/msmtprc
nano editor has opened a new blank file for you, enter the following and replace the example configuration as needed. I’m including examples for two domains so you get the idea.
# Account: domain1.com
# Set a default account to use
account default : domain1
# Account: domain2.com
Repeat as necessary to add more domains. Save your changes by typing
Control-O and pressing Enter. Then type
Control-X to exit the editor.
Virtual Host Configuration
Assuming you’re using PHP with Apache as your web server, you can add the last two lines in the example below to each virtual host to specify which configuration account you’d like to use to send mail.
DirectoryIndex index.html index.php
# MSMTP configuration for this domain
php_admin_value sendmail_path "/usr/bin/msmtp -a domain1 -t"
domain1 with the correct domain obviously. This should correspond to the account names specified in the
Alternatively you need to instruct your middleware or framework to use MSMTP instead of Sendmail/Postfix to send mail and pass the same account parameter whenever called. Most have some form of configuration option to allow this.