Customise Password Recovery Email
The majority of web applications need some sort of authentication component, and ASP.Net's authenication is excellent and allows you all the functionality you would expect.
On a recent web application we were required to provide users with the facility to recover their password, and as you'd expect there is a PasswordRecovery component that you just drop on a page and it works.
Unfortunately the emails that resulted from the control were not as rich as the client required. i.e HTML and Plain text alternate views, the HTML alternate view also used linked resources so the mail arrives in your mailbox with all its images attached. No need to download the images.
After a little bit of thought it was easy to override the PasswordRecovery mails using the SendingMail event.
protected void PasswordRecovery1_SendingMail(object sender, MailMessageEventArgs e)
{
string pwd = Membership.GetUser(PasswordRecovery1.UserName).GetPassword(PasswordRecovery1.Answer);
ProfileCommon UserProfile = Profile.GetProfile(PasswordRecovery1.UserName);
// send custom email at this point.. insert custom mail here
// cancel the component's email here
e.Cancel = true;
}
This simple code allows you to override the component's standard email and extract the user's password. With this information you can then insert your own custom mail object and send the recovery information to the user using a template of your choice...
Job done.. Hope this helps you out