?
Solved

How to customize the e-mail sent by PasswordRecovery In The SendingMail Event and Include The Newly Reset Password In The E-mail?

Posted on 2009-05-19
4
Medium Priority
?
1,342 Views
Last Modified: 2013-11-07
Hi,
I have a multi-lingual application that needs to send different password recovery e-mail messages to the user based on their language preference.  The problem is that I cannot simply read one .txt file from the MailDefinition of the PasswordRecovery control due to this and when I try to programatically customize the e-mail sent by the system the <% Username %> and <% Password %> tokens are not being replaced.

How can I customize the e-mail message sent to the user when they are resetting their password and include the new password in the e-mail?

Please note that I get an error when I manually try to reset the password in the SendingMail event, but I could not find another way to obtain a reset password for the e-mail.
Protected Sub PasswordRecovery1_SendingMail(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.MailMessageEventArgs) Handles PasswordRecovery1.SendingMail
        Dim strFinalBody As String = TryCast(GetGlobalResourceObject("Emails", "PasswordResetBody"), String)
 
        Try
            Dim usr As MembershipUser = Membership.GetUser(PasswordRecovery1.UserName)
            'Returns object not set to an instance of an object error
            'Passwords are hashed and only resets are enabled.
            Dim password As String = usr.ResetPassword(PasswordRecovery1.Answer)
 
            MsgBox(password.ToString)
 
            e.Message.From = New MailAddress("test@test.com")
            e.Message.CC.Add(New MailAddress("devemail@test.com"))
            e.Message.Subject = TryCast(GetGlobalResourceObject("Emails", "PasswordResetSubject"), String)
            'Perform subsitution
 
            strFinalBody = strFinalBody.Replace("&lt;% UserName %&gt;", PasswordRecovery1.UserName)
            strFinalBody = strFinalBody.Replace("<% Password %>", password)
 
            strFinalBody = strFinalBody.Replace("<%UserName%>", PasswordRecovery1.UserName)
            strFinalBody = strFinalBody.Replace("<%Password%>", password)
 
            strFinalBody = strFinalBody.Replace("&lt;% UserName %&gt;", PasswordRecovery1.UserName)
            strFinalBody = strFinalBody.Replace("&lt;% Password %&gt;", password)
 
            strFinalBody = strFinalBody.Replace("&lt;%UserName%&gt;", PasswordRecovery1.UserName)
            strFinalBody = strFinalBody.Replace("&lt;%Password%&gt;", password)
 
            e.Message.Body = strFinalBody
            e.Message.IsBodyHtml = True
        Catch ex As Exception
            MsgBox(ex.Message.ToString)
            Response.Redirect("~/Errors/Error.aspx")
        End Try
    End Sub

Open in new window

0
Comment
Question by:endrec
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 4

Expert Comment

by:TimSledge
ID: 24428032
FireMail by ceTe Software might be helpful to you.

http://www.cete.com/Products/FireMailForNET/index.csp
0
 

Author Comment

by:endrec
ID: 24428228
Please note I just want to have the username and password token replacement work in the PasswordRecovery control by overriding the SendingMail method of the PasswordRecovery control.
0
 
LVL 2

Accepted Solution

by:
ilaird earned 2000 total points
ID: 24932929
You are on the right track by accessing the message via the event

I would use localization via resx files to achieve your multi lingual support. You can also get the current requesting browsers language with request.browser.language you can also use something called browsercaps to beef up the results a little better.

resx files will automatically check for the appropriate language if you have set it via the cultureui property, which i usually set in the global asax

i use something like
protected void Application_BeginRequest(object sender, EventArgs e)
        {
            CultureInfo ci = null;
            try
            {
                ci = CultureInfo.CreateSpecificCulture(Request.UserLanguages[0]);
            }
            catch
            {
                // default for bad user setting
                ci = new CultureInfo("en-US");
            }
            Thread.CurrentThread.CurrentCulture = ci;
            Thread.CurrentThread.CurrentUICulture = ci;
        }

which will cause the resx to bounce between strings.resx or strings.es-ES.resx when you request the resource string.

0

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question