在电子邮件标题中列出取消订阅。怎样做?

发布于 2024-10-06 16:58:01 字数 2392 浏览 4 评论 0原文

我正在尝试将列表取消订阅标头添加到正在发送的电子邮件中。到目前为止,我还没有尝试这样做。

到目前为止我得到的是:

var mailMessage = new MailMessage
                    {
                        Subject = newsletter.Subject,
                        Body = newsLetterHTML,
                        IsBodyHtml = true,
                        Sender = new MailAddress(senderAddress)
                    };
                    mailMessage.To.Add(subscriber.Email);
                    mailMessage.ReplyToList.Add(senderAddress);
                    mailMessage.Headers.Add("List-Unsubscribe", unSubscribeUrl);

unSubscribeUrl 类似于“www.example.com/unlist?id=8822772727”。 当我发送电子邮件时,除了列表取消订阅选项之外,一切正常。这在任何邮件客户端中都没有显示。

欢迎任何帮助!

更新
这是我用于发送电子邮件的完整代码:

var mailMessage = new MailMessage
                    {
                        Subject = newsLetter.Subject,
                        Body = newsLetterHTML,
                        IsBodyHtml = true,
                        Sender = new MailAddress(senderAddress)
                    };
                    mailMessage.To.Add(subscriber.Email);
                    mailMessage.ReplyToList.Add(senderAddress);
                    mailMessage.Headers.Add("List-Unsubscribe", String.Format("<{0}>", "http://www.foo.com/unlist?id=8888"));
                    mailMessage.HeadersEncoding = Encoding.Default;

                    var smtpClient = new SmtpClient();
                    smtpClient.Send(mailMessage);

更新 2
经过一番研究后,我将标题放入了 mailMessage 中。当我发送电子邮件时,我可以看到以下标题:

List-Unsubscribe: <http://demo.localhost/home/hobbymap-gerard/afmelden-voor-nieuwsbrief?id=c786aeb0-554d-4670-94d8-82d6f25a050b>
MIME-Version: 1.0
From: [email protected]
To: [email protected]
Reply-To: [email protected]
Date: 8 Feb 2011 09:50:22 +0100
Subject: Test met plaatje
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: quoted-printable  

但是当我在任何客户端中打开电子邮件时,我在客户端中看不到取消订阅按钮?我还做错了什么吗?

I'm trying to add a List-Unsubscribe header to my e-mail that is being sent. So far I hadn't any luck trying to do so.

What I have got so far:

var mailMessage = new MailMessage
                    {
                        Subject = newsletter.Subject,
                        Body = newsLetterHTML,
                        IsBodyHtml = true,
                        Sender = new MailAddress(senderAddress)
                    };
                    mailMessage.To.Add(subscriber.Email);
                    mailMessage.ReplyToList.Add(senderAddress);
                    mailMessage.Headers.Add("List-Unsubscribe", unSubscribeUrl);

The unSubscribeUrl is something like 'www.example.com/unlist?id=8822772727'.
When I sent the e-mail everything works fine except for the list-unsubscribe option. Which is not shown in any mail client.

Any assistance would be welcome!

UPDATE
This is the whole code I use for sending the email:

var mailMessage = new MailMessage
                    {
                        Subject = newsLetter.Subject,
                        Body = newsLetterHTML,
                        IsBodyHtml = true,
                        Sender = new MailAddress(senderAddress)
                    };
                    mailMessage.To.Add(subscriber.Email);
                    mailMessage.ReplyToList.Add(senderAddress);
                    mailMessage.Headers.Add("List-Unsubscribe", String.Format("<{0}>", "http://www.foo.com/unlist?id=8888"));
                    mailMessage.HeadersEncoding = Encoding.Default;

                    var smtpClient = new SmtpClient();
                    smtpClient.Send(mailMessage);

UPDATE 2
After a little research I got the header into the mailMessage. When I sent an email I can see the following headers:

List-Unsubscribe: <http://demo.localhost/home/hobbymap-gerard/afmelden-voor-nieuwsbrief?id=c786aeb0-554d-4670-94d8-82d6f25a050b>
MIME-Version: 1.0
From: [email protected]
To: [email protected]
Reply-To: [email protected]
Date: 8 Feb 2011 09:50:22 +0100
Subject: Test met plaatje
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: quoted-printable  

But when I open the email in any client I can't see the unsubscribe button in the client? Am I doing something else wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

最初的梦 2024-10-13 16:58:01

大多数电子邮件客户端仅支持 mailto-links。

尝试一下,它应该始终有效:

mailMessage.Headers.Add("List-Unsubscribe", "<mailto:[email protected]?subject=unsubscribe>");

RFC 指定也可以使用 http 链接。
但我发现,如果您包含 http 链接,电子邮件客户端将不再显示取消订阅链接。我认为这是因为人们可能只能访问邮件协议。

所以这并不总是有效:

 mailMessage.Headers.Add("List-Unsubscribe", "<http://www.host.com/list.cgi?cmd=unsub&lst=list>, <mailto:[email protected]?subject=unsubscribe>"; 

Most email clients only support mailto-links.

Try this, it should work always:

mailMessage.Headers.Add("List-Unsubscribe", "<mailto:[email protected]?subject=unsubscribe>");

The RFC specifies it is possible to use http-links also.
But i've found that if you include http-links, the email clients no longer shows the unsubscribe link. I think it's because of the possibility that people only have access to the mail protocol.

So this does not always work:

 mailMessage.Headers.Add("List-Unsubscribe", "<http://www.host.com/list.cgi?cmd=unsub&lst=list>, <mailto:[email protected]?subject=unsubscribe>"; 
枕花眠 2024-10-13 16:58:01

除了其他答案之外,还有 RFC-8058 需要另一个标头才能启用 HTTPS链接取消订阅功能:

List-Unsubscribe:<https://example.com/unsubscribe.html?opaque=123456789>
List-Unsubscribe-Post: List-Unsubscribe=One-Click

List-Unsubscribe-Post 标头应具有值 List-Unsubscribe=One-Click。这是为了防止反垃圾邮件软件意外取消订阅,并允许显示带有取消订阅按钮的网页的额外步骤。

某些电子邮件客户端不会处理没有 List-Unsubscribe-Post 标头的 List-Unsubscribe 链接。

In addition to other answers, there is also RFC-8058 that requires another header to enable HTTPS link unsubscribe functionality:

List-Unsubscribe:<https://example.com/unsubscribe.html?opaque=123456789>
List-Unsubscribe-Post: List-Unsubscribe=One-Click

List-Unsubscribe-Post header should have a value List-Unsubscribe=One-Click. This is to prevent accidental unsubscribe by anti-spam software and allow an extra step of displaying a web page with an unsubscribe button.

Some email client will not process List-Unsubscribe links without List-Unsubscribe-Post header.

何其悲哀 2024-10-13 16:58:01

根据 List-Unsubscribe 网站,URL 应该用尖括号括起来,例如 <代码>

您可以尝试以下操作:

mailMessage.Headers.Add("List-Unsubscribe", String.Format(
    CultureInfo.InvariantCulture, "<https://{0}>", unSubscribeUrl));

为确保您不会被标记为垃圾邮件,请确保拥有 SSL 认证域。

According to the List-Unsubscribe website, the URL should be wrapped with angle brackets, e.g. <https://www.example.com/unlist?id=8822772727>.

You can try something like:

mailMessage.Headers.Add("List-Unsubscribe", String.Format(
    CultureInfo.InvariantCulture, "<https://{0}>", unSubscribeUrl));

To ensure you are not flagged as spam make sure to have an SSL Certified domain.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文