Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

Customize body of Email sent by passwordrecovery in asp.net

Jan 8, 2012
Introduction:

In this article I will explain how to customize body of email sent by passwordrecovery control in asp.net membership.

Description:

In many sites we will see option like forgot password whenever we click on that option and give username or password they will send password details to our email.


We can achieve this functionality by using passwordrecovery control in previous post I explained clearly how to Recover forgot password using passwordrecovery control in asp.net membership. After implement Recover forgot password concept with passwordrecovery control we will get default plain format of email like below 

If we want to customize this default email message format we need add some properties in our passwordrecovery control. Now I will explain how to customize body of email using passwordrecovery control in asp.net membership.

To change the body of email message we need to create a separate email template that contains required email body content. After implement Recover forgot passeword right click on your website add new folder and give name as “EmailTemplate”. After create folder right click on that and add new text file and give name as “CustomMail.txt” and add content to text file like this

Your password has been reset, <%UserName%>

According to our records, you have requested that your password be reset. Your new
password is: <%Password%>

If you have any questions or trouble logging on please contact a site administrator.

Thank you!
If you observe above text file content we will find two placeholders those are <%UserName%> and <%Password%> . Our Passwordrecovery control automatically replaces these two placeholders with username and recovered password.

Now select your passwordrecovery control right click on it and select properties and point our email template (text file) to BodyFileName property in Mail Definition section

In properties window select Mail Definition >> BodyFileName >> select our email template (text file)

After completion of all changes run your application enter username, answer and check your email body that will be same as our text file just like this 


If we want to send mail with HTML format we need to set IsBodyHtml property to true in Mail Definition and update your email template to include HTML tags (Ex: <b>UserName</b>; <b>Password</b>) Sample output mail after Html tags that would be this 



If you enjoyed this post, please support the blog below. It's FREE!

Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email

6 comments :

Anonymous said...

gud

Anonymous said...

Hello dear
kya aap bata sakte hai ke" Image ke sath name bhi aye textbox ke search se from database just like facebook friends search"
plz reply me i am wait for .............i need in my project .............

sekhar mekala said...

namespace Yceeya.CustomPasswordRecovery
{
[ToolboxData("<{0}:CustomPasswordRecovery runat=server>")]
}

In this code will store only one varible.plz tell me i want multiple values,how can i write code.

Anonymous said...

hi i did not get password recovery output lot of errors coming ..pls what i have to write code in c# using membership concept

MP3 said...

Hi there, i've got all of this working however I want to replace the UserName portion that gets sent in the email instead to the User's EmailAddress instead, do you know of a way? I simply replace the <%UserName%> with <%EmailAddress%>?

Mark said...

Suresh
Thanks for this. Just implemented a custom password reset message. It went exactly as you describe here.
And I agree, the default message is no good for a commercial site with thousands of users who aren't programmers.
Well done because I spent a lot of time trying to find how to do it in MSDN itself and could not find a description of how to do this.
Take care
C Flattener

Give your Valuable Comments

Other Related Posts

© 2010-2012 Aspdotnet-Suresh.com. All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.