Handling bouncing e-mails

I am using Mailgun to send emails from Discourse, and the server linked above to receive emails.

2 Likes

If you want Discourse to stop sending mail after hitting a bounce threshold, you need a webhook from Mailgun to fire at your Discourse, and then configure the threshold in the settings.

I’m unsure what this all means at this point, but it sounds like you have two questions:

  1. How to handle bounced email, and
  2. Seeing all mail logs from incoming mail

These are two different things. This topic here is for setting up webhooks so your outgoing mail providers let Discourse know what’s bouncing.

The topic you followed (at Straightforward direct-delivery incoming mail) has a troubleshooting section. But receiving mail to your server and bouncing messages sent from your server are two separate issues.

4 Likes

It means that the incoming mail server can receive incoming emails. As I understand, it should be enough to handle bounces? Or am I missing something and I still need webhooks?
As I understand, to handle bounces I just need to set the “reply by” address and then when the delivery fails my server will receive a reply (with the verp key in the address) and push it to Discourse.

An email can fail to be delivered because of many different reasons, and there are several methods those failures can be reported back to your forum. Most of the time the sending email service is able to detect the failure as it happens, this is what the webhooks are for. (Possibly Mailgun etc use VERP internally, I’m not sure).

VERP is another method which can handle bounces when Mailgun etc think the email was successfully sent but the final target mail server rejects it. I’m not sure if Mailgun etc will decide that the email was successfully sent after only one email relay succeeds or if it can detect failures further away. I’m also not sure when VERP will be used; from my experience it is not a common method. And, unfortunately, it seems to me that it isn’t actually handled by Discourse (at least not if you’re also using Mailgun and webhooks).

So yes, you need to set up the webhooks or else you will miss out on 99.5% of your bounces.

1 Like

I’m failing in setting up the Bounce for the Amazon SES. Done as mentioned below, but no bounces show in the Admin/Emails/Bounces. Tried it on several instances and I always have the same issue. I’ve tried using the Amazon SES API but it doesn’t seem to work with Discourse. Any ideas?

Amazon Simple Email Service (AWS SES)

  • Log in to the AWS console, and go to Simple Email Service (SES)
  • Under Domains , find the one you use for your forum, and click it
  • Under the Notifications section, click “Edit Configuration”
  • All of the SNS settings can be set to “No SNS Topic”
  • Under “Email Feedback Forwarding”, choose Enabled
  • Save Config
1 Like

Discourse sends via SMTP. Does the Amazon SES API use SMTP? If not, then that’s why.

5 Likes

After delivery failures I get this error in Mailgun logs, is it normal or did I setup something incorrectly?
Why it tries to send an email to https:// URL?

{
	"severity": "permanent",
	"tags": [],
	"storage": {
		"url": "https://se.api.mailgun.net/v3/domains/<MY_FORUM>/messages/......==",
		"key": "......=="
	},
	"delivery-status": {
		"attempt-no": 1,
		"message": "",
		"code": 406,
		"description": "",
		"session-seconds": 0.7080450057983398
	},
	"recipient-domain": "www.<MY_FORUM>",
	"event": "failed",
	"campaigns": [],
	"reason": "generic",
	"user-variables": {},
	"flags": {
		"is-routed": false,
		"is-authenticated": true,
		"is-callback": true,
		"is-system-test": false,
		"is-test-mode": false
	},
	"log-level": "error",
	"timestamp": 1581170444.087084,
	"envelope": {
		"sender": "postmaster@<MY_FORUM>",
		"transport": "http",
		"targets": "https://www.<MY_FORUM>/webhooks/mailgun"
	},
	"message": {
		"headers": {
			"to": null,
			"message-id": "20200208140040.1............@<MY_FORUM>",
			"from": "postmaster@<MY_FORUM>",
			"subject": null
		},
		"attachments": [],
		"size": 3130
	},
	"recipient": "https://www.<MY_FORUM>/webhooks/mailgun",
	"id": "..........."
}

btw for some reason Mailgun seems to fail to deliver to Yahoo =\ (it’s our first Yahoo signup)

1 Like

@Alex_P, take a look at these posts.


2 Likes

I think it’s not related, it was not OpenID, just a standard signup.

Anyway my main question was not related to Yahoo:

1 Like

Oh, I must’ve misunderstood.

1 Like

I had this error before, but for a different IP address. It seems Yahoo is picky about some IP addresses, but I don’t think there’s really anything you can do to change their opinion of those addresses. Raise a support ticket at Mailgun and ask them to change your assigned IP address.

1 Like

Yeah, I created the ticket, they changed IP, but it’s banned by Yahoo too :joy:

But the question was not about Yahoo, it’s the same for all failed emails

1 Like

It’s not trying to send an email to a web page, that’s the address for your hook so that your forum knows the email was rejected.

3 Likes

No, it was saying that it’s spam (even though before and after that it worked fine :thinking:). There also was a link to mail.ru support form, I contacted them and they replied that it was fixed,

Ah, yeah, I just noticed that it says

It’s weird though that this entry in the log is marked as failed too. Is it normal?

And there is nothing in admin/email/bounced and admin/email/rejected :thinking:
And in the user profile (e.g. the yahoo one which still fails) the bounced email counter is 0.

1 Like

If your Discourse site setting is set to “login required” then you should use an API key to authenticate these incoming webhook requests, correct?

No. They should just work.

1 Like

Interesting in my environment, when I test the webhook without the API auth header, I get an error, when I add the api-key and api-user to the head, then I get a 200/OK.

3 Likes

What webhook are you using?

1 Like

For my webhook, I’m using: http://your.discourse/webhooks/postmark

In my case this is: https://discourse.clcohio.org/webhooks/postmark

1 Like

Hmm.

I know that I didn’t use an API key when I did my testing. Are you posting to that path? Something like:

      post "/webhooks/postmark.json", params: {
        "Type" => "SoftBounce",
        "MessageID" => message_id,
        "Email" => email
      }

Does it work if you turn off login required? (If that’s the case, then it sounds like a bug.)

5 Likes