Monday, December 15, 2014

UnSubscription Email Utility

In this post I am going to show a very simple yet very useful utility which everyone of us encounter when we get lots of unwanted mails which we had subscribed sometime in our web exploration but later we want to get rid of those subscribed mails. Moreover this is a very integral part of our business use cases.

I have used ASP.NET MVC as an example but if you understand the concept, this can be achieved using any of your favorite programming logic as well.

I tried to keep the example as simple as possible so that I can cover the concept/business logic in more details. In this example as soon as I run the application I will call the Index action method with my hardcoded email id. In real world you might want to make it more dynamic and will try to pass this as a parameter.

image

Now I have written a utility  method which is used to generate the subscription link, which can be embedded in the marketing emails, so when the user click on this link Say Unsubscribe Me, he will land on the page where just in a click of button his mail id will be removed from the marketing email database.

image

For the simplicity sake of this example I have not used the real time database operations but for your implementation you will definitely need DB operation to update the user preferences.

Not let me highlight the most important logic of this GetUnSubscriptionLink method; since we are dealing with one key information of a user which is his email id, so I have used CryptoHelper utility which is used to Encrypt the email id of the consumer. This will also help us to filter any Brute force attack where the hacker will try to enter random emails on his list to invoke the unsubscribe methods.

You can download your copy of CryptoHelper utility from here: http://1drv.ms/1r2kisl

One of the example of the unsubscription link is shown in the screen below. For better programming practice you can configure the root URL in your config file.

image

Additionally you can do a second level of validation where you can prompt the end user to provide his email id in a text box and validate this against the decrypted string containing the email id from the query string, if both has a match then unsubscribe otherwise ignore the unsubscribe request.

In my example as soon as you pass all the validation I am calling the Unsubscribe action method of my controller which takes the encryptedText as a parameter and decode the text to unsubscribe the user from marketing emails.

image

Sample screen once the user is unsubscribed

image

I am providing below a utility Property which I found somewhere on internet, this might be very useful to you if you are playing with URL’s

image

Crypto Helper Utility: http://1drv.ms/1r2kisl

You can download the full working copy of this example from this link: http://1drv.ms/1vU5ZCO

Hope this helps, let me know in comments if you have any trouble in downloading the files or understanding my thoughts Smile

0 comments:

Post a Comment