Our ZenPhoto install wants to be able to notify us when there are new comments. I also may eventually want to set up exception notifications for some of my dynamic sites. At least for now, I don’t want to run a full-blown mail server for our domains; I don’t want to deal with spam detection and restricting who can use the mail server to relay mail, etc. But I know that many of the common Unix email servers can be configured so that they don’t receive mail and only send mail if it originates on one or more specific servers. I don’t have a lot of experience setting up mail servers. The ones I am most familiar with are qmail (which is what ArsDigita used everywhere) and Postfix. I am betting that it will be easier to set up Postfix on Ubuntu so let’s look for some instructions.
Installing Postfix
There are some promising looking instructions on the Digital Ocean
site - for Postfix on Ubuntu 14.04. Postfix is apparently the default
mail server for Ubuntu because sudo apt-get install mailutils
installs postfix as one of the “additional packages”. The install
process asked me two questions: what kind of mail server configuration
I needed (I chose ‘Internet Site’), and what is the domain name for
the mail server. I debated whether I should leave this set to the
hostname for the server, which is a subdomain of one of our domains,
or if I should set it to just the domain. Tim may have our domain name
registrar set up for email forwarding for the domain so it may be
slightly safer to configure this mail server with the subdomain. And
it will make it a lot clearer to me where the email is coming from.
Configuring Postfix to only accept mail from localhost
The installer had set up Postfix to listen on all available
interfaces. So netstat -ltpn
shows
So, following the instructions,
I edited /etc/postfix/main.cf and changed inet_interfaces = all
to
inet_interfaces = localhost
and restarted the postfix service. Now I
see postfix only on the local interface (ipv4 and ipv6):
I tested email sending with: echo "test email body" | mail -s "Test
email" cnk@<destination>
and it went through just fine. YEAH!
Now, I need to forward system mail (e.g. root mail) to me. To do this,
I need to add a line to /etc/aliases for root + the destination
emails. Then I got the new entries in /etc/aliases
into
/etc/aliases.db
by running the newaliases
command. I tested the
new root works by sending a second test email:
echo "test email body" | mail -s "Test email for root" root
And this
one also got to me.
There was an additional section about how to protect my domain from being used for spam - especially in this case, being impersonated. The article on setting up an SPF record doesn’t look too hard - if the service we are using to do DNS lets us set that up. I’ll have to look into it when we are switching DNS.
Configuring Email in ZenPhoto
Having the ability to get root mail is good - but the main reason I wanted email on this server was for ZenPhoto’s comment functionality. So now, on the plugin page of the ZenPhoto admin site, there is a Mail tab with two options. For now I chose zenphoto_sendmail which just uses the PHP mail facility to send mail using the local mail server.