Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to generate link for unsubscribing from email

I have a simple rails app where user can send a mass email to 10+ people. In this email I'd like to always have a link at the bottom which the end user can click to unsubscribe himself from the notifications. I don't have much idea how I should tackle this.

can there be just a generic link in the email which users click then enter their email address to unsubscribe themselves? But problem with this is that some other user could unsubscribe someone else.

I would like to generate a specific unique link for each email so that when user clicks it, it automatically removes that user from the list rather than user having to do some extra work.

Where should I start in order to implement this?

like image 968
Patrick Avatar asked Aug 02 '10 11:08

Patrick


People also ask

How do I create an unsubscribe link in email?

Click the Email tab. Select the Include unsubscribe link checkbox. To choose which phrase you want appear for your unsubscribe link, click Edit link text, then in the dialog box, select the radio button next to the link text that you want. Click Save.

Where do I find my unsubscribe link?

An unsubscribe link is a link that allows subscribers to opt out from receiving marketing emails sent by a particular brand. It is usually placed in the email footer and leads to the unsubscribe page.

How do I create an unsubscribe link in Outlook?

- Choose View all Outlook Settings. - Under Mail, click "Compose and reply". - On the top part, that's where you would be able to edit your signature. - Once there, you can add a link on your signature with this format: <a href="URL">Unsubscribe</a> or any code provided.

Can I create an unsubscribe link in Gmail?

If you'd like to allow your email recipients to unsubscribe from your emails, you can use Unsubscribe Links. To use Unsubscribe Links, create a campaign. In the MergeMail pane on the right, click on Advanced , then enable the Add Unsubscribe Link check box.


1 Answers

Your unsubscribe links could look like this: http://host/application/[email protected]&token=598bbdf39bc8f27b07fe85b6a7dd8decef641605

Generate the token using the email address and a magic token. Ideally, you'd use HMAC with SHA256, but even just sha1 should be 'good enough':

$ echo "secret token [email protected]" | sha1sum
598bbdf39bc8f27b07fe85b6a7dd8decef641605  -

The secret token portion would be fixed in your application, and the [email protected] needs to match the email address.

Of course, if the secret token ever gets revealed, you're back to anyone unsubscribing everyone. You could also store per-user magic tokens in your database to validate the tokens in URLs, that wouldn't be much more difficult than this, and definitely much safer.

like image 55
sarnold Avatar answered Sep 21 '22 11:09

sarnold