I would just like to add something for anyone that arrives on this question in 2019.
I don't have the reputation level to leave a comment in response to Krzysztof's comment, so I am posting this as an answer. His comment was left in 2017 and was valid then. However, in 2019, all ports EXCEPT 25 are open on Google cloud - including 587 (TLS) and 465 (SSL).
If you are using compute engine and sending mail, you MAY need to configure a firewall rule allowing outbound traffic for the port YOU are using! This is not readily apparent. Check this if you try to send on any port other than 25 if things aren't working. 25, as I stated, is blocked. Here is a link to show you how to do this on an instance. It is toward the bottom of the page as of June 2019. It is simple to do.
https://cloud.google.com/compute/docs/tutorials/sending-mail/
AS OF JUNE 2019 HERE ARE THE STEPS TO SET UP A FIREWALL RULE FOR OUTGOING EMAIL IF YOU HAVE A COMPUTE ENGINE VM:
- Go to the Create a Firewall Rule page. (Sign into your Google Cloud account where you ALREADY have your compute engine VM and put this into the browser after you do - https://console.cloud.google.com/networking/firewalls/ )
- Choose a name for the firewall rule.
- Under Network, select the network hosting the VM instance that you intend to send emails from.
- Under Direction of traffic, select Egress.
- Under Targets, choose the appropriate target for this rule. For example, you might choose Specified target tags if you want the rule to apply to instances that have a specific tag.
- Under Destination filter, set 0.0.0.0/0 if you want to allow egress traffic from the VM instance to any destination. If you want to limit the destination, enter another IP range here. THIS IS IMPORTANT IF YOUR EMAIL IS HOSTED SOMEWHERE ELSE.
- Under Protocols and ports, select Specified protocols and ports > tcp and enter 2525.
- Save your changes.
Here is a link to how to set up things to send emails (compute engine) -
https://cloud.google.com/compute/docs/tutorials/sending-mail/
Here is a tutorial for setting up the FROM email accounts. All email accounts must be from Google Hosted accounts. For example, I host a website on Google Cloud so I would need to set up the email accounts my mail will come from with Google, but I can use their service to send emails as long as I do (app engine)-
https://cloud.google.com/appengine/docs/standard/python/mail/#who_can_send_mail
Here is a tutorial for sending email using php on Google Cloud in 2019 (App Engine)-
https://cloud.google.com/appengine/docs/standard/php/mail/sending-receiving-with-mail-api
Here is another tutorial for sending email from Google in 2019 (compute engine)-
https://cloud.google.com/compute/docs/tutorials/sending-mail/
As Johan pointed out in a comment below my answer, I didn't include the text of the documents I linked to. However, I didn't do that because the document text can change, as we have seen many times with Google Cloud, and I personally hate when I come to Stack Overflow and go down a path based on instructions here only to find that the process changed months ago. So I think, in this narrow case and for now, the links to the documents may be best.