Google Compute Engine does not allow outbound connections on ports 25, 465 and 587. These SMTP ports are blocked by default due to abuse.
For sending emails through the Google cloud compute instance Google recommends the following:
- Relay emails through your G suite(formerly known as Google Apps) account
- Relay using third party email service such as Sendgrid, Mailgun or Mailjet.
- Connect your instance to your network via VPN and use your network to send email
With setting up the relay service we would need to configure and install Postfix. We won’t be installing and configuring Postfix on this tutorial. Instead we would be utilizing a WordPress WP Mail Plugin that would allow us to use a Gmail SMTP to send emails. I recommend setting up a new gmail account just for this purpose.
On Gmail setup do the following
- Go to https://myaccount.google.com and sign in if not already signed in
- Click on Sign-in & Security
- Scroll down the bottom under Apps with account access
- Enable Allow less secure apps
On WordPress setup do the following
- Go to your WordPress administrator panel
- Go under WordPress plugin and click on Add New search “WP Mail Plugin”
- Click on Install Now and Activate the plugin after
- Click on WP Mail Settings then fill in the following
- Then click Save
- Next try testing the settings work. Click on Email Test tab
- Type an email address and hit Send Email
That should be it, hit up the comments below if you get stuck with any of the setup.