views:

36

answers:

3

I have an ASP PasswordRecovery module on a page, the code comes up like this:

<asp:PasswordRecovery ID="PasswordRecovery1" runat="server">
    <MailDefinition From="[email]">
    </MailDefinition>
</asp:PasswordRecovery>

However, when I submit the form I just get the message, "We were unable to access your information. Please try again."

I saw this question and made sure to add those attributes to my web.config here:

<providers>
    <remove name="CustomizedMembershipProvider"/>
    <add name="CustomizedMembershipProvider"
        type="System.Web.Security.SqlMembershipProvider"
        connectionStringName="MessageBank"
        applicationName="MessageBank"
        minRequiredPasswordLength="6"
        minRequiredNonalphanumericCharacters="0"
        requiresQuestionAndAnswer="false"
        enablePasswordReset="true"
        enablePasswordRetrieval="false" />
</providers>

The email is working fine because the app sends emails regularly throughout the day. But it's not sending recovery emails for some reason.

Here's the relevant web.config section:

<mailSettings>
    <smtp from="[email]">
        <network host="[host]" password="[password]" userName="[username]"/>
    </smtp>
</mailSettings>

UPDATE: I added a function to handle the "SendingMail" event:

Protected Sub PasswordRecovery_submit(ByVal sender As Object, ByVal e As WebControls.MailMessageEventArgs) Handles PasswordRecovery.SendingMail

I added a break point in this function but it is never reached, the above error message just comes up in the app. Any other ways to debug what's going wrong?

A: 

Have you remembered to declare your smtp section in your web.config? By default the password recovery control uses this during it's execution.

<system.net>
<mailSettings>
<smtp deliveryMethod="Network">
<network
defaultCredentials="True"
host="localhost"
port="25"
from="[email protected]"/>
</smtp>
</mailSettings>
</system.net>
Brian Scott
Yes. As specified in the question, emails are working fine, the app sends dozens each day. I edited my question to post the section, are those other attribute necessary for the password recovery?
DisgruntledGoat
@Brian Scott: On further investigation, I realized that we have a special function that is sending the email so I assume the default email system wasn't working. Is there a way to call my custom function? As mentioned above, the app isn't getting to PasswordRecovery.SendingMail before the error.
DisgruntledGoat
@DisgruntledGoat: One thing you can do is simply place the SMTP element into your web.config file with dummy values as shown. Then you can hook onto the "SendingMail" event whereby you can cancel the event to cancel the default mailing behaviour as well as provide your own custom email logic instead. I know you said that the app wasn't making it to the "SendingMail" event but is that maybe because you have not declared the "MailSettings" element in yor web.config which it depends upon?
Brian Scott
+1  A: 

That error message is the default UserNameFailureText

Are you sure you are entering a valid user name?

Hugh Jeffner
A: 

Here is how I solved the problem. As mentioned in the comments on Brian's answer, our app is using a custom email function (not 100% sure why but the regular SMTP stuff just doesn't work). Anyway, you can simply hijack the PasswordRecovery.SendingMail event:

Protected Sub PasswordRecovery_submit(ByVal sender As Object, ByVal e As WebControls.MailMessageEventArgs) Handles PasswordRecovery.SendingMail
    ' do custom email sending here, using the variables in e.Message 

    e.Cancel = False
End Sub
DisgruntledGoat