title: Email not working from Google Cloud Compute Engine Ubuntu VM through Google Apps
body: <p>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.</p>
  
  <p>I know that Google <a href="https://cloud.google.com/compute/docs/tutorials/sending-mail/" rel="nofollow noreferrer">always blocks port 25</a> on Compute Engine instances, but they also point to some <a href="https://support.google.com/a/answer/2956491" rel="nofollow noreferrer">documentation</a> 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.</p>
  
  <p><strong>CURRENT STATUS:</strong>
  I was able to get it to work for several hours by doing some <a href="https://serverfault.com/questions/759807/configure-postfix-to-use-google-apps-smtp-relay-in-a-google-compute-engine-insta">research</a>, 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:</p>
  
  <pre><code>Aug 18 17:17:56 my-master-compute-engine2 postfix/error[18060]: A7812BCE13: to=&lt;myemail@gmail.com&gt;, 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)
  </code></pre>
  
  <p>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):</p>
  
  <pre><code># 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 &amp; compute engine doesn't support ipv6
  inet_interfaces = loopback-only
  inet_protocols = ipv4
  </code></pre>
  
  <p>How can I fix this specific issue, or find a work around?  Thanks!</p>