How to configure Discourse to receive email from Mailgun?

I have a fully working Discourse installation (installed using the recommended approach) on a server (Linode) running Ubuntu. I can send email without issue and do new user sign-up.

We are using this feature Configuring incoming email to create new topics or group messages : Discourse needs to provide an incoming email address.

In mail gun I have created a Catch All route that forwards email to a webhook as described here: Discourse Mailgun Routes and I have installed the plugin.

However, looking at the Mailgun logs this fails. Any ideas how to do this?

{
	"timestamp": 1737657789.428326,
	"recipient-domain": "forum.domain.com",
	"envelope": {
		"transport": "http",
		"targets": "https://forum.domain.com/mailgun/routes/receive_mime",
		"sender": "me@myemail.com"
	},
	"primary-dkim": "",
	"delivery-status": {
		"code": 406,
		"session-seconds": 0.277,
		"message": "Not Acceptable",
		"attempt-no": 1,
		"description": ""
	},
	"event": "failed",
	"id": "4uIIPrRRTQOwluJaE-QpRA",
	"campaigns": null,
	"log-level": "error",
	"tags": [],
	"message": {
		"size": 4089,
		"headers": {
			"message-id": "CA+riLLnyMLCruT2DmhFjTuyvy7OtQ8NrT0X0m5PZXfK3uzwCEg@mail.gmail.com",
			"to": "domain+support-12@forum.domain.com",
			"subject": "Test",
			"from": "Me Me <me@myemail.com>"
		},
		"attachments": []
	},
	"recipient": "https://forum.domain.com/mailgun/routes/receive_mime",
	"user-variables": {},
	"flags": {
		"is-test-mode": false,
		"is-authenticated": false,
		"is-routed": false,
		"is-system-test": false
	},
	"storage": {
		"region": "us-east4",
		"env": "production",
		"key": "BAABAAAVXB5iOt41fPtDZaekVDDH1beaZA",
		"url": "https://storage-us-east4.api.mailgun.net/v3/domains/forum.domain.com/messages/BAABAAAVXB5iOt41fPtDZaekVDDH1beaZA"
	},
	"severity": "permanent"
}

The easiest and recommended way is to Configure direct-delivery incoming email for self-hosted sites with Mail-Receiver

2 Likes

If you enable mailgun_log_rejections and send another email, there should be a rejection reason in your sidekiq logs (mailgun does not retain the response body so this is basically the only way) and that should tell you.

Otherwise you can use the mail-receiver setup if you would rather do that.

1 Like

Hi @Wolftallemo thanks for the excellent plugin :slight_smile:

I did check /logs but could not see anything related to this issue. I’m not sure if this is the correct place to read the sidekiq logs or not?

I would prefer to get the plugin working, might give it a few more days before attempting the mail-receiver. My installation is behind a traefik reverse proxy so I’m sure it will be a little more difficult that way.

Regards,

Dan

Yes that is where they would be, although that’s unusual.

I would start with checking the inbound spam filter. It’s possible it’s set to not filter on mailgun’s end.

If this is the case, I would either:

  • Change inbound spam filtering on mailgun’s end to add the spam headers (which is in domain settings)
  • Set mailgun_spam_detection to none (but I don’t recommend this)

But I suppose setting it to none could be a rather easy test here too.

Hello,

Those settings already seem to be in place. This is probably something very dumb I am doing. I had a quick go with the mail-receiver; the only issue is I am running behind a Traefik reverse proxy, so I will no doubt need a few attempts to get that to work with all the required docker compose labels, etc. This is why I liked your plugin so much!

Are you successfully receiving bounces from mailgun by any chance? The only two reasons it would be getting rejected without a log are either: you have the wrong key set (it specifically has to be the webhook signing key) or you don’t have it set at all.

Would double-check if you accidentally set something other than the webhook signing key (because the wording within Discourse is somewhat questionable and should probably be changed).

The mail receiver works on port 25,so treafik does not need to know about it.

I already changed my MX records now so to avoid another 24-hour delay, I’m going to persevere with the mail-receiver approach.

This simplifies things very much. In this case, I can more or less just run the sample script without any changes or integration with the traefix/docker-compose stack?