繁体   English   中英

如何配置 SendGrid 取消订阅链接以不将 email 添加到任何取消订阅列表?

[英]How can I configure the SendGrid unsubscribe link to not add the email to any unsubscribe lists?

我的应用程序发送 email 时事通讯。 我正在使用 SendGrid。 我想使用 SendGrid 的订阅跟踪来提供面向用户的取消订阅界面,因为它对取消订阅 URL 进行身份验证,并设置了一个List-Unsubscribe header,其中包括mailto:方法。

我想跟踪我的数据库中的取消订阅。 我使用 SendGrid 的取消订阅 webhook 事件来执行此操作:当用户单击取消订阅 URL 或发送到List-Unsubscribe地址时,SendGrid 会为我触发取消订阅 webhook。

到目前为止,这是我的代码,它有效:

// Sending a newsletter

import * as sgMail from '@sendgrid/mail';
sgMail.send({
  customArgs: {
    newsletter_id: 'cats',
  },
  to: 'foo@bar.com',
  from: 'me@app.com',
  trackingSettings: {
    subscription_tracking: {
      enable: true,
      substitution_tag: '--unsubscribe--',
    },
  },
  html: '<a href="--unsubscribe--">Click here to unsubscribe</a>'
});

// Then, in SendGrid webhook endpoint:

const webhookEvents = await extractSGWebhookBody(req);
for (const ev of webhookEvents) {
  if (ev.event === 'unsubscribe') {
    const newsletterId = ev['newsletter_id'];
    const accountId = ev[EMAIL_TAG_ACCOUNT_ID];
    dbUnsubscribe(ev.email, newsletterId);
  }
}

但是,除了触发 webhook 之外,SendGrid还将email 地址添加到其自己的全局取消订阅/禁止列表中。 这是不可取的,因为我有两个地方可以跟踪取消订阅。 它们会因为许多原因而失去同步(例如,如果用户在应用程序内重新订阅,SendGrid 将不会知道)。

所以,我想禁用 SendGrid 的取消订阅列表。 我只想将其取消订阅功能用作代理:用户单击取消订阅,然后 SendGrid 向我发送一个 webhook。

如何阻止 SendGrid 的退订 URL 将用户的 email 地址添加到自己的退订列表中?

最好让 SendGrid 成为取消订阅的真实来源,这样您就不会意外地向已取消订阅该组的用户发送 email。 但是,您可以使您的应用程序与 SendGrid 保持同步。

为了阻止您的应用程序与 SendGrid 不同步,有用于重新订阅的 Event Webhooks 因此,如果用户通过 SendGrid 重新订阅,您的应用程序可以知道它。

如果用户通过您的应用程序重新订阅,您的应用程序需要删除抑制(取消订阅记录),以便 SendGrid 将再次发送给该用户。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM