Configure VERP to handle bouncing e-mails

Setting up bounces handling

Discourse uses the Variable envelope return path (VERP) technique to handle bouncing e-mails.

To enable VERP, set the “reply by email address” site setting with an email address template that uses the + sign. The default of

replies+%{reply_key}@discourse.example.com

… works fine. If you are using your own or your company’s email server, then, that’s it :tada:

Your discourse instance must be able to receive email sent to this address. This should work via POP, but we highly recommend Direct-delivery incoming email for self-hosted sites

If, however, you are using a third party email service, you will need to enable VERP, or activate their webhooks as follows:

MailGun

  1. Log in to MailGun and go to your dashboard; look in the left column for the SendingWebhooks page.
  2. Make sure that the correct Domain is selected (top right on desktop)
  3. In Discourse, set the mailgun api key site setting with your HTTP webhook signing key
  4. Click the Add webhook button, set the “Event Type” menu to “Permanent Failure”, and set the URL to https://your.discourse/webhooks/mailgun
  5. Repeat the Add webhook portion, choosing “Temporary Failure” as the “Event Type”
    • :exclamation: there is a “Test webhook” section which is useful for testing, but doesn’t save - make sure you use the Add webhook button instead

SendGrid

  • Log in to SendGrid and go to Mail Settings
  • expand the Event Webhook setting and enable it if it isn’t already
  • click edit to set the HTTP POST URL to http://your.discourse/webhooks/sendgrid
  • make sure you selected the following 3 actions: Dropped, Deferred and Bounced
  • save your changes by clicking the :white_check_mark:

MailJet

  • Log in to MailJet and go to event tracking
  • check the bounce event
  • set the endpoint URL to http://your.discourse/webhooks/mailjet
  • check the :white_medium_square: in the group events column
  • click the save button

SparkPost

  • Login to SparkPost and go to your dashboard.
  • Select Account from left menu icons
  • Select Webhooks from menu ( SparkPost )
  • Select New Webhook.
  • Enter a friendly value for Webhook Name e.g. Discourse Forum
  • Enter a Target URL as http://your.discourse/webhooks/sparkpost
  • Select Add Webhook.

Amazon Simple Email Service (AWS SES)

  • On Discourse:
    • set reply by email enabled and reply by email address as per the top of OP
    • set manual polling enabled
  • On AWS:
    • create an SNS Topic
    • create an SNS Subscription for the created Topic as HTTPS pointing to https://your.discourse/webhooks/aws
    • go to SES > Verified Identities, select your site domain, and go to the Notifications tab. Edit your Feedback Notifications. Set the Bounce feedback and Complaint feedback to the SNS Topic you just created

Postmark

  • Login to Postmark and then select the server that is used for sending Discourse emails
  • Select the message stream associated with Discourse emails, typically Default Transactional Stream
  • Click Webhooks
  • Click Add webhook
  • Enter Webhook URL as http://your.discourse/webhooks/postmark
  • Under, Which events should we send?, check Delivery and Spam complaint
  • Scroll down and click Save webhook

Testing Bounces

To ensure that everything is working, do this:

  1. Sign up for a new account on your site with an obviously incorrect email, of the form bademail@obviously-invalid-domain.com or clearly.nobody.has.this.email.address@gmail.com
  2. Wait a while for the emails to fully bounce (check your provider’s logs, if you want – they will usually be shown under the “warn” or “error” log level)
  3. Check /admin/email/bounced on your site to confirm that the bounce was picked up. Bear in mind this may take up to 48 hours depending on how many retries and the particular logic of your email provider.

Configuring Bounces

Bounces handling can be customized using these site settings

  • soft bounce score: points added to the user’s “bounce score” when we receive a temporary bounce from their email address
  • hard bounce score: points added to the user’s “bounce score” when we receive a permanent (or unknown) bounce from their email address
  • reset bounce score after days: number of days during which we must receive no bounce before we can reset the user’s “bounce score” back to 0
  • bounce score threshold: score threshold at which point we will stop sending non urgent emails to the user

Last Reviewed by @SaraDev on 2022-07-19T20:00:00Z

50 Likes

If someone wants to test this out and confirm that it works, I’ll add it to the OP.

Create Mailgun webhooks

for event_type in 'permanent_fail' 'temporary_fail'; do
curl -s --user 'api:'=mg_api_key= \
          https://api=mg_region=.mailgun.net/v3/domains/$discourse_hostname/webhooks \
          -F id="$event_type" \
          -F url="https://=discourse_hostname=/webhooks/mailgun"
done

Updated the Mailgun section as things have changed a wee bit in their UI:

4 Likes

Is there a simple way to handle email complaints automatically currently using VERP? For the case of users who do not unsubscribe but just mark the email as spam. It’s quite critical to stop emailing people who complain.

2 Likes

Just kind of FYI to everyone with low level skills: SES part is badly outdated, I reckon.

Just don’t choose FIFO even it is suggested :man_facepalming:

1 Like