Reputation: 1859
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?
Upvotes: 26
Views: 34686
Reputation: 1
back then in 2010, most email clients didn't support the URL option and they only supported mailto: addresses in List-Unsubscribe
header to which they would send an email when a user clicks the unsubscribe button and you'd need to handle it at the mail server level. It's only recently that the popular email clients started supporting the URL and Google and Yahoo said that they are going to make it a necessary requirement in 2025 for senders with large volumes. You can optionally add a List-Unsubscribe-Post
header along with List-Unsubscribe
in which case, the client won't navigate the user to the specified URL and only sends a post request to it so that anti-spam bots does not accidentally unsubscribe a user by GETting the url for inspection. Ideally, you may put both mailto: and http links in that header and process both.
Upvotes: 0
Reputation: 1765
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.
Upvotes: 10
Reputation: 262979
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.
Upvotes: 5
Reputation: 211
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>";
Upvotes: 21