I\'d like to customize the \"unsubscribe\" links in our email newsletters so that they remove the recipient with a single click. Right now they just point to a generic page
If your mailing list software uses old-school best practices, there should be an 'unsubscribe' email address - emailing to that address from the address you want to unsubscribe (possibly with a fixed subject line) generally does the trick (along with sending a confirmation email). In that case, adding a properly formatted 'mailto' link should do the trick.
I give each email I send an ID, then look up the email ID when they click unsubscribe.
http://www.foo.com/unsubscribe.asp?ID=1234
And then unsubscribe the email address I sent 1234 to.
Two reasons for not having a plain text email address in the query the in the URL are that you don't want malicious users unsubscribing your customers from your mailing list.
The second which probably would only affect companies sending millions of e-mails, is to make it harder for spammers to 'sniff' for genuine email addresses.
It's not safe to embed email addresses in a newsletter. Not sure about yours but many newsletters ended up in some archive on the web. There are spam bots specifically designed to harvest addresses from mailing list archives.
Email is a safer technology for this. Setup a mail account for unsubscribe and get Email address from mail headers. If you use any mailing list software, it should handle this already.
I assign a unique 32-character identifier string (with MySQL: MD5(UUID())
) to each e-mail address and only submit that identifier in the unsubscribe link.
You can encode a URL like so:
http://yourserver.com/unsubscribe/<encoded-email>/<expiration>/<signature>
Where <signature>
is something like HMAC(secretkey, "<encoded-email>/<expiration>")
. Encoded-email can just be a URL-encoding of the email, or it can be an actually encrypted (AES+CBC+Base64 or similar) version of the email. Using full encryption would seem to be of little use though - since the person receiving this has their own email address anyway.
This signature scheme has the advantage of not needing any database storage, while remaining secure against malicious attempts to unsubscribe someone.
Alternately (or in addition to the above), you can send a confirmation mail out to confirm the user's intent. This avoids problems if the user forwards the email.