How to set up postfix on nginx server to allow WP send emails through aka ( via SMTP with TLS auth or similar set up?

February 3, 2014 12.6k views
Hi there. Sorry for the noob question, but I'm pretty new on managing a vps and It seems DO community lacks a few articles regarding setting up an email server properly. I running a 1GB VPS powered by Ubuntu 12.04 and I successfully installed a LEMP Stack (nginx, php5-fpm, mysql and Wordpress), so everything was running smoothly and working 100% (performance, W3 total cache etc.), my website was scoring 80/100 on Google PageSpeed, CPU consume was low and stable, however, as soon as I started configuring Ubuntu to allow PHP/Wordpress to send emails (let's say contact form 7 submissions, wp email notifications), then my nightmares began. Since my Droplet was created, I got DNS records properly configured to allow my domain respond on servers, this means that I'm able to login to my email accounts by typing and then I'm redirected to site so that I can login with and have complete access to my mailbox, send/receive emails etc. While I was on my old shared hosting I used to rely on the same configuration, however, my wordpress site was able to send emails through PHP mail( ) function as also with the help of a plugin "WP Mail SMTP", which can be configured to send emails via SMPT with TLS authentication. Then I started reading the articles available here on DO about postfix, Exim, Sendmail, "SMTP as relay for Gmail and Hotmail on postfix" etc., but even after following these tutorials strictly I couldn't enable php/wordpress to send emails on my server. I don't need a full email server running on my VPS, I just want my web applications to be able to send emails through a account with TLS authentication. I've taken a snapshot of my droplet on its stable stage (LEMP + Wordpress fully working) and everything email related untouched, and since I've messed a lot with postfix, Exim and sendmail I had to rebuild my droplet from the snapshot so that I could proceed on my attempts to get email working again. Has anyone configured Ubuntu or other Linux distro properly to enable php/wordpress to send emails through a third party service such as gmail or hotmail? I really need this to work because this is the only thing compromising the development environment I'm trying to set up on my VPS. Thanks in advance for your help.
4 Answers
The easiest solution would be sending mail straight from the droplet and not through Outlook (i.e. through the mail() function).

You can do that by installing an MTA such as postfix:
DEBIAN_FRONTEND=noninteractive sudo apt-get install postfix
Then edit Postfix's config to listen on the loopback interface only:

Once you've done that, try sending emails using the php mail() function, does it work?
  • I stuck in mail not send issue via function wpmail().
    Just run ```DEBIAN
    FRONTEND=noninteractive sudo apt-get install postfix``` in droplet email can send to receiver.

    Thank you kamaln7.

Hi. Thanks for your reply. While researching I've come across this article, but bypassed it giving the fact I was a bit lost with all available (not so promising) options.

Could you please tell me if this set up would work if I had a few virtual hosts running wordpress (currently 3 light traffic wordpress web sites) and each one has its own domain?

I don't want to mess up everything again and then have to rebuild my Droplet one more time. Although I understand everyone has a specific usage/demand regarding sending emails from the server or through a relay configuration, It would be great if postfix, sendmail or any other stable MTA came pre-configured for the most common usages on DO Droplets.

Again, thanks for your help. I'll try this solution and research about it a bit more, but a few weeks ago I had never touched terminal on mac/linux before, and now I'm running a high performance server with ubuntu, nginx, wordpress and a few caching techniques, and compared to my old shared hosting, my web sites are blazing fast.

While trying to manage for the first time ever my own VPS, I've gained a lot experience, as also I've learnt a couple new interesting things etc., however, my lack of "sysadmin" knowledge is leading me on spending too much time on research, trial and error and this is compromising my production.

I'm starting to think that maybe I haven't made the right choice, and now I'm seriously considering moving on to a managed WP hosting such as WP Engine. So sad :(
Sounds like you I had a nightmare of a time setting up emails to work. I've been at it for almost 3 days on just this issue. Finally got it to work following this tutorial:

My personal setup:

Configured MX records for microsoft Outlook which I've been incredibly impressed with. I'm talking about the web version which used to be hotmail. So far it seems to be a cleaner email system than gmail or yahoo and you can set it up with your own domain name for free unlike gmail which charges you $50/year for their google apps version. You'll need to google search this though.

Then wait until the MX records on digital ocean are all set (up to 24 hours) and go activate your Outlook mail with your domain instead of

Once I could send/recieve emails from this, I just had to follow the tutorial at the above link.

I did not have to install postfix or anything else on my server for this to work.
After an exhaust reading of a bunch of articles all around the web, as also the ones available here on Digital Ocean, I struggled during a whole week of research with no success, then, after getting in touch with DO support team, it simply turned out to be an "ANTI SPAM Procedure" imposed by Digital Ocean.


If you're struggling such as I did, fire up a support ticket within your account's admin panel and ask Digital Ocean if the SMTP functionality has any kind of initial block already set on your VPS .

This is a short line extracted from the message I got from DO support:

--"To curb a recent increase in abuse and SPAM, we have a initial SMTP block on new accounts created in certain contexts. To remove that block we'd like to do some manual account verification."--

So they'll probably request you some additional information and maybe a few documentation to verify your identity, and then they'll finally unblock your SMTP functionality.

I just needed to follow DO tutorial on installing postfix and everything mail related is working now.

I suppose DigitalOcean do this to reinforce your accordance on not performing any acts made illegal by the CAN-SPAM Act on their TOS:

Again, It is important that you take some time to review the email restrictions specified in their Terms of Service. It might be of great help in order to guide you towards a better understating of Digital Oceans use policies.

I hope this helps anyone else coming through this issue.

Best regards,

Have another answer? Share your knowledge.