窗外

Linux VM on Azure: A Mail Server

I need a mail server which can serve emails with my own domains for a small group of users. I don’t want to go with Exchange server as it is too heavy. With some search on the internet, I decide to setup a small Linux node with Postfix on Azure. Such a small node only costs about $40/month which can be covered by my MSDN subscription, and it is good enough for the purpose.

I choose to setup the VM with Ubuntu server image. There are a lot of posts online about how to setup Postfix on Ubuntu. Particularly, I followed this one as I also need the virtual domain and virtual mailbox. It is quite clear and easy to follow, and I got the Postfix and Dovecot up and running by following it.

The missing parts of the above post are the anti-spam and anti-virus portion. Fortunately, Amavis-new + Spamassassin + Clamav make things a lot more easier. The Ubuntu help page here is good enough for the purpose.

With all these setup, I have a mail server which can send and receive emails. However, when I try to send emails to those big mailbox hosts like gmail or outlook, my emails are rejected as they don’t accept emails from dynamic IP range, which is unfortunately used by the public cloud vendors like Azure and AWS. So the only way to workaround it is to relay emails to a mail delivery service. With Azure, we can leverage SendGrid. SendGrid has a free plan for Azure accounts of which the quota is 25,000 / month. So I create a SendGrid account in Azure, and configure Postfix to relay emails to it. SendGrid has a short guide for it.

The only problem I encounter with the relay is that Amavis-new throws an error “TLS is required, but was not offered
by host”. With some search, I find the workaround here. After fixing it, the emails can be accepted by gmail and outlook happily.

Leave a Reply

Your email address will not be published. Required fields are marked *