How to send emails on server with 25/465/587 outbound blocked?


(Vencent S) #1

Recently I switch my host provider to Google Cloud Platform. Everything works great until I found outgoing mail traffic is blocked by Google.

Google Compute Engine does not allow outbound connections on ports 25, 465, and 587
See Sending Email from an Instance  |  Compute Engine Documentation  |  Google Cloud for detail.

Google advises using SendGrid, Mailgun, or Mailjet. However, since I didn’t see any Mailgun plugin for Discourse (two repo on GitHub indeed, but one hasn’t been updated since 2015, and the other even breaks the rebuild of Discourse), I formerly use SMTP to send emails via Mailgun, but this way has been blocked by Google. So my site’s email system is totally breaking down.

Is there any solution?


(Bhanu Sharma) #2

You don’t need a plugin to use mailgun with discourse. However, it is also very clear that if all 3 ports are blocked then you won’t be able to use mailgun.

You can try going with elasticemail they support port 2525 which is very rare to be blocked.


(Vencent S) #3

hmmmmm…I think using their API is the “native” way to use Mailgun and SMTP is just for compatibility. I don’t know if I’m right. But I think it may be feasible to use another server as a relay via an SSH tunnel. I have no idea how to actually do this. But I noticed there are some people doing this way, though they are not for Discourse. Theoretically, it should work.


(Bhanu Sharma) #4

Theoretically is very different than IRL

Discourse does not support sending through API and this has been discussed earlier multiple times. This won’t be implemented unless there is a single, open source standard to send emails via API.

Individual developers may make plug in for discourse but it won’t really help in any way as email is required at the time of first run in order for admin to recieve the activation email.

Though it may be possible to install a plugin at that phase, it is neither recommended nor is documented anywhere by discourse in their official install guides.

I highly doubt someone is going to work on
A. Creating a plugin
B. Writing a guide to compile discourse with their plugin
C. Maintain a plugin for discourse for as long as discourse exists and the API standard doesn’t.

That too Just to add a functionality that is product specific and isn’t reliable.

One solution can be to run something like a local smtp2api script that takes all details from the SMTP and then sends it via API. That still would require a lot of effort and time.


(Jay Pfaffman) #5

If you use port 2525 as @itsbhanusharma recommended it will work with all mail delivery services that I have tested. I have done dozens of installs this way.

Another solution would be to develop a plugin that delivers mail through the API. Thus far, no one has seen the need to do that. If you have a budget of $1000 or more, you could post in #marketplace and see if anyone is interested in developing one.


(Michael Brown) #6

Yet more possibilities:

  • IPsec (or some other opaque tunnel) to a mailserver you control
  • maybe there is an HTTPS SMTP transport agent for e.g. postfix, so you can have postfix listen for local mail but submit outside over HTTPS

(Vencent S) #7

Wow, you saved my day! Though it is not officially documented by Mailgun, this approach does work.


(Bhanu Sharma) #8

I bet it is indeed documented here:

This Page clearly states:

Google Compute Engine allows port 2525 for SMTP submission.


Cannot Get Mailgun to send admin email