Configure o VERP para lidar com e-mails devolvidos

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 curtidas

Se alguém quiser testar isso e confirmar que funciona, eu adicionarei ao OP.

Criar webhooks do 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

Atualizei a seção do Mailgun, pois algumas coisas mudaram um pouco na interface deles:

4 curtidas

Existe uma maneira simples de lidar com reclamações de e-mail automaticamente usando VERP atualmente? Para o caso de usuários que não cancelam a inscrição, mas apenas marcam o e-mail como spam. É bastante crítico parar de enviar e-mails para pessoas que reclamam.

2 curtidas

Só para informar a todos com poucas habilidades: a parte de SES está muito desatualizada, eu acho.

Não escolha FIFO, mesmo que seja sugerido :man_facepalming:

1 curtida

Olá @pfaffman, obrigado por compartilhar isso, mas uma ajuda rápida, por favor.

E se eu estiver usando um provedor de e-mail diferente da lista anterior, ainda é possível?

2 curtidas

Nos meus logs, o endpoint webhooks/mailjet produziu um aviso:

Recebeu um webhook do Mailjet, mas nenhum token foi configurado. Este é um comportamento inseguro e será desautorizado no futuro.

Em /admin/site_settings/category/email?filter=mailjet existe o campo “Token de webhook do Mailjet”, sem instruções sobre como configurá-lo corretamente.

Fui para Mailjet e adicionei ao campo Endpoint URL: https://discourse.example.org/webhooks/mailjet?t=[seu_token]

Substituí [seu_token] por um gerado por um Gerador de Tokens e inseri o mesmo valor no campo “Token de webhook do Mailjet” em /admin/site_settings/category/email?filter=mailjet.

Isso parece ter eliminado os avisos de log.

1 curtida

Só queria observar que confirmei que as reclamações de spam para AWS SES são enviadas de complaints@email-abuse.amazonses.com para o ‘Endereço de e-mail de resposta’ (nas configurações do Discourse) e são tratadas como devoluções incondicionais pelo Discourse atualmente através da configuração VERP padrão (sem webhooks SNS).

Acabei de encontrar isto, que pode ser útil para alguns que também usam o SES (a secção ‘Utilizar o simulador de caixa de correio’):

Pode usar o ‘enviar um e-mail de teste’ dentro da administração do Discourse para enviar para endereços específicos que simularão devoluções e reclamações sem prejudicar a sua reputação de envio.

por exemplo:

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

Existem outros endereços de teste no link acima.

1 curtida