SendGrid Unable to deliver List-Unsubscribe Email Header to Yahoo and Outlook

788 Views Asked by At

I am trying to send emails using SendGrid Api using python. I have already handled how to add list-unsubscribe header while sending emails and I have been successful in doing so, gmail get unsubscribe header only. I am getting email on yahoo, outlook but not unsubscribe header.

Now this is what I have been doing, you'll notice an extra code, I'm adding subject in mailto url and passing an encoded string which is a requirement.

{
  "personalizations": [
    {
      "to": [
        {
          "email": "[email protected]"
        }
      ],
      "subject": "Your subject line here"
    }
  ],
  "from": {
    "email": "[email protected]"
  },
  "headers": {
    "List-Unsubscribe": "<mailto:[email protected]?subject=unsubscribe:encoded_string>, <http://www.unsubscribe.example.com>"
  }
}

Here, endode_string is originally a query string containing ids, user and other information that is need to unsubscribe a person. To encode, we are using the following code. message:string is what we encoding.

cipher = AES.new(cipher_secret_key.encode(), AES.MODE_ECB)
encoded = base64.b64encode(cipher.encrypt(message.encode()))

The output of encryption is given.

bYFgnNbtHMbI6nO8dWBPpuYhEKPHI5H0m4ufZCWoL1g~|eyAicmNwdF90byI6ICJtdW5lZWIuNjVoYXNzYW5AZ21haWwuY29tIiwgInRlbmFudF9pZCI6ICJjb3Vyc2VyYSIsICJjdXN0b21lcl9pZCI6ICIxIiwgIm1lc3NhZ2VfaWQiOiAiMDA0MDdmMzM0NDVmOGIwODA1ZTAiLCAic3ViYWNjb3VudF9pZCI6ICIwIiB9

And that is where things go southway, gmail is okay with this but yahoo and outlook are not. You can check out the difference for Gmail and Yahoo dealing with unsubscribe header Yahoo vs Gmail

I'll go ahead and paste the Yahoo Raw Message output.

List-Unsubscribe: 
 =?us-ascii?Q?=3Cmailto=3Abcsf15m021=40pucit=2Eedu=2Epk=3FO=3Dunsubscribe=3AbYFgnNbtHMbI6nO8?=
 =?us-ascii?Q?dWBPpuYhEKPHI5H0m4ufZCWoL1g~|eyAicmNwdF?=
 =?us-ascii?Q?90byI6ICJtdW5lZWIuNjVoYXNzYW5AZ21haWwuY?=
 =?us-ascii?Q?29tIiwgInRlbmFudF9pZCI6ICJjb3Vyc2VyYSIs?=
 =?us-ascii?Q?ICJjdXN0b21lcl9pZCI6ICIxIiwgIm1lc3NhZ2V?=
 =?us-ascii?Q?faWQiOiAiMDA0MDdmMzM0NDVmOGIwODA1ZTAiLC?=
 =?us-ascii?Q?Aic3ViYWNjb3VudF9pZCI6ICIwIiB9=3E?=

Problem, its getting disturbed, you'll notice 3C is hex for < [less than sign]. What might be causing this ? Is Yahoo mailing server expecting a string that should include certain characters. I experimented and put upto 24 characters and it went and header was receiving for Yahoo and sadly above this limit it start generating the output like i posted above.

1

There are 1 best solutions below

0
On

The encoding you are seeing is normal and should not cause issues. It happens in Gmail as well, but Gmail is in the habit of decoding it before it shows it to you. If you go to Show Original > Download Original you will see this.

I am not clear on what the actual issue is that you are having. If it is just this encoding there is nothing to worry about.