Search code examples
c#emailsmtpgmaillist-unsubscribe

How to add unsubscribe link as shows in below image


I've written code in C# that send mail to number of users. The email is in HTML format and contains a unsubscribe link.

What I want to do is, have unsubscribe link as shown in image... enter code here

To add more information, I'm using SendGrid for sending emails to end users.

I viewed raw message format in Gmail and I can see Header there in format

List-unsubscribe: <https..../usersettings?SubscriberId=VioR5IcgvSIosfB1w%2FCPfhpyGBdko%2BxsmFTAsQAemuWgSJkpTP1UeDg%2BW4frl59A0KVVpiK0lI7IrS3N1BCm0Sspd0dqEaJGlKHAY3g7IR3INwkyJEAmfU55TBJ8uEo%3D>

Yet the link is not displayed. What am I missing?


Solution

  • You have to add that link in your email header something like this

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