I’ve been working on Google Cloud Compute Engine to set up servers for hosting all kinds of e-commerce related stuff. One of the more unknown areas to me here are the mailservers; they are complex in setup, very dependent on and specific to the environment they run on and even harder to debug if you don’t know what you’re doing.
So as you can guess the problem was my Magento 1.9.x installation not sending all the emails out. At first, the server didn’t send any email at all as expected; it wouldn’t work magically by itself. So I installed and configured postfix on Nginx, which got the
mail() function running. Then I installed the SMTP Pro extension for Magento to route all transactional emails via Gmail/Google Apps, and all seemed well. Until we saw that though order-emails were sent, no tracking- or shipping mails went out. Thoroughly confused why some mails would sent and others wouldn’t, I took to debugging.
I saw that though the
mail() function was present and working, it didn’t actually deliver any mail. A simple test script told me the mail was sent succesfully, I never received it. Checking
/var/log/syslog I saw these errors:
Sep 25 08:37:09 gcp-instance postfix/smtp: connect to ASPMX.L.GOOGLE.COM[188.8.131.52]:25: Connection timed out
Sep 25 08:37:39 gcp-instance postfix/smtp: connect to ALT1.ASPMX.L.GOOGLE.COM[184.108.40.206]:25: Connection timed out
This pointed me towards a problem with port 25, so I tried checking to see if that would work by running
telnet aspmx.l.google.com 25 and as expected, it would try indefinitely. Blocking port 25 turns out the be standard practice for ISPs because of it’s often use for spam servers. Going down that road led me to the GCP documentation (I feel stupid for not looking this up at the start to begin with..) which confirms all my findings. I’m going to have to use SMTP relay via Gmail to get this working, so let’s get cracking.
The documentation describes the steps and settings to take in the GApps Admin. I added an SMTP relayservice for addresses in my domain-pool and allow them only from the IP address of my instance. Let’s see if this is enough to get things working, because Postfix still will try to access port 25. TBC!