Search code examples
ubuntugmailgoogle-compute-enginepostfix-mta

Email not working from Google Cloud Compute Engine Ubuntu VM through Google Apps


I'm very new at sending email from a server, and am only trying to set up email on my VM so I can have it send crontab emails (and later on some python scripts will need to send out random notification type emails). On my Amazon Linux EC2 box this all just worked right off the bat but I'm having issues on a GCCE Ubuntu 16.04 instance.

I know that Google always blocks port 25 on Compute Engine instances, but they also point to some documentation that seems to suggest that I can still send email using an SMTP relay through Google Apps. I specifically do not want to use a 3rd party service like SendGrid, so this seems like my best (only?) option. However, that documentation ^ doesn't seem specifically written for GCCE.

CURRENT STATUS: I was able to get it to work for several hours by doing some research, and did successfully receive emails from my crontab jobs. However, the next morning I had to restart the instance and since then (no other change points) my mail.log is just filled with this error, and I am no longer receiving emails:

Aug 18 17:17:56 my-master-compute-engine2 postfix/error[18060]: A7812BCE13: to=<[email protected]>, relay=none, delay=50875, delays=50874/0.13/0/0, dsn=4.4.2, status=deferred (delivery temporarily suspended: lost connection with smtp-relay.gmail.com[173.194.74.28] while performing the HELO handshake)

My postfix config file is below, my 'myorigin' file just contains my domain name, and I have configured all this in the SMTP relay in advance Gmail settings of Google Apps for my domain (allowing mail only from specified IP address--my vm external ip--and am not requiring SMTP Authentication or TLS encryption):

# Google Apps Relay SMTP, must use Port 587 because, 25 is blocked
relayhost = [smtp-relay.gmail.com]:587
# a file which should contain the google apps domain
myorigin = /etc/mailname

# Force ehlo behavior
smtp_always_send_ehlo = yes
smtp_helo_name = my.vm.external.ip # vm external ip (same that is configured in smtp relay in google apps)

myorigin = /etc/mailname
mydestination = $myhostname, my-master-compute-engine2.c.random-stuff.internal, localhost.c.random-stuff.internal, , localhost
mynetworks = 127.0.0.0/8 my.internal.ip.address/32 [::1]/128 [fe80::]/64
mailbox_size_limit = 0
recipient_delimiter = +

# limit smtp to loopback interface & compute engine doesn't support ipv6
inet_interfaces = loopback-only
inet_protocols = ipv4

How can I fix this specific issue, or find a work around? Thanks!


Solution

  • Never figured out how to get it to work using the setup documented by Google, but I was able to get a simpler, basic SMTP relay set up through a different random Gmail address I made following the steps here.