- Issue created by @TrevorBradley
- 🇨🇦Canada TrevorBradley
Again, this patch is not ideal - open to ideas as to how this should be solved.
I think I may have stumbled on to a fault in the SMTP module for one click unsubscribe.
I'm trying to get posts sent out via the SMTP module to be correctly handled by Gmail. I thought everything was set up just right, though I noticed that SMTP took the capitalized List-Unsubscribe and List-Unsubscribe-Post headers and uncapitalized them to "list-unsubscribe" and "list-unsubscribe-post".
This decapitalization is done by SMPTMailSystem::mail() on line 217:
$headers = array_change_key_case($message['headers']);
Unfortunately, Gmail appears to be EXTREMELY picky about these headers. If list-unsubscribe or list-unsubscribe-post are not properly capitalized, Gmail will provide the unsubscribe link, but clicking on it does nothing.
If I patch SMTPMailSystem to re-capitalize these two headers, take my email sent to Gmail and click on the unsubscribe link, my web server gets a POST request as described in RFC 8058. That post request comes in from Mountain View, CA (home of Google)
In your hook_mail implementation, add in List-Unsubscribe and List-Unsubscribe-Post headers as described in RFC 8058:
$message['headers']['List-Unsubscribe'] = t('<@host/unsubscribe-request/@data>',['@host' => $host, '@data' => $data]);
$message['headers']['List-Unsubscribe-Post'] = t('List-Unsubscribe=One-Click');
Note that the mail sent out uncapitalizes these headers
Note that when this mail is received by GMail, the Unsubscribe link shows up, but clicking on it does not send a POST request to the referenced server in list-unsubscribe.
... Not quite sure here. I'm going to supply a quick patch to SMTPMailSystem to watch for these headers and re-capitalize them. This seems like a poor solution, but I need something that works pretty quickly.
Alternate suggestions to ensure the capitalization of these headers are welcome.
Patch to come, will post here if I learn anything else.
Active
1.0
Code
Again, this patch is not ideal - open to ideas as to how this should be solved.