Discourse on Google Cloud Platform Unable to Send Email Using SparkPost

Recently we’ve moved our free cloud hosting from Amazon Web Services AWS (1-year Free Tier) to Google Cloud Platform GCP (1-year Free Tier). As we were moving away from AWS, we also need to change our transactional email provider from AWS SES to SparkPost (Free). However we encountered a problem when setting up new Discourse on Ubuntu 16.04 LTS using GCP. The installation went successfully but during sign up for admin account, no email was sent to the predefined admin email address.

Problem: Unable to send email using SparkPost from Discourse instance on Google Cloud Platform

We tried troubleshooting using the following command:
telnet smtp.sparkpostmail.com 587
and it became clear that the server instance could not reach SparkPost SMTP.

Another problem after resolving the above problem was email was blocked by SparkPost due to policy. In other words, the email was stopped from being sent out by SparkPost due to some restriction.

Solution: Use port 2525 instead of 587 & change the default from email Discourse uses

For the first problem, found the solution from SparkPost support:

Alternately, port 2525 can be used in environments where port 587 is blocked (such as Google Compute Engine).

It can be solved by editing containers/app.yml to change the port from 587 to 2525 and rebuilding the app.

For the second problem, found the solution from SparkPost support:

Change the default from email Discourse uses

By default, Discourse will send email from the hostname you configured Discourse with. For instance, if you set the DISCOURSE_HOSTNAME setting to ‘discourse.mysite.com’, Discourse will send emails with the from address noreply@discourse.mysite.com.

To change this, uncomment and edit this line in your Discourse installation’s app.yml file:

Note that you should replace “your-sending-domain.com” with the sending domain you created and verified earlier.

You’ll need to issue a rebuild after uncommenting the above line and setting the from email address as required.

This is an useful article with step by step by SparkPost support on how to set up email for Discourse: Using SparkPost with Discourse