配置VERP以处理反弹电子邮件

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

51 个赞

如果有人想测试一下,并确认它是否有效,我会把它添加到 OP 中。

创建 Mailgun 网页钩子

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

更新了 Mailgun 部分,因为他们的 UI 有一些小变化:

4 个赞

目前是否有简单的方法可以使用 VERP 来自动处理电子邮件投诉?针对那些不取消订阅但仅将电子邮件标记为垃圾邮件的用户。停止向投诉的用户发送电子邮件至关重要。

2 个赞

仅供技能水平较低的各位参考:SES 部分估计已经严重过时了。

即使系统建议,也请不要选择 FIFO :man_facepalming:

1 个赞

你好 @pfaffman ,感谢分享,但请快速帮忙解答一下:

如果我使用的是上面列表中未列出的其他电子邮件提供商,是否仍然可行?

2 个赞

在我的日志中,端点 webhooks/mailjet 产生了一个警告:

收到了一个 Mailjet 网页钩子,但未配置令牌。这是不安全的行为,将来将被禁止。

/admin/site_settings/category/email?filter=mailjet 中有一个“Mailjet 网页钩子令牌”字段,但没有关于如何正确设置的说明。

我去了 https://app.mailjet.com/account/triggers,并在“端点 URL”字段中添加了:https://discourse.example.org/webhooks/mailjet?t=[your_token]

我将 [your_token] 替换为由 Token Generator 生成的一个令牌,并在 /admin/site_settings/category/email?filter=mailjet 的“Mailjet 网页钩子令牌”字段中输入了相同的值。

这似乎消除了日志中的警告。

1 个赞

我想指出,我已经确认,AWS SES 的垃圾邮件投诉会从 complaints@email-abuse.amazonses.com 发送到“回复电子邮件地址”(在 Discourse 设置中),并且在目前标准的 VERP 配置下(没有 SNS 网页钩子),会被 Discourse 视为硬退订。

发现这个,对使用 SES 的人可能也有用(“使用邮箱模拟器”部分):

可以在 Discourse 管理后台使用“发送测试邮件”功能,向特定地址发送邮件,从而模拟退信和投诉等情况,而不会损害你的发送声誉。

例如:

bounce@simulator.amazonses.com
complaint@simulator.amazonses.com

上面链接中还有其他测试地址。

1 个赞