views:

391

answers:

2

Hi,

I am using the ASP.NET membership provider controls (ChangePassword and PasswordRecovery) and they generally work just fine.

Unfortunately they don't send any emails once the process is finished.

I set up the SMTP server using the ASP.NET Configuration Website and it added the following lines to the web.config:

<system.net>
 <mailSettings>
  <smtp from="[email protected]">
   <network host="pagetailors.de" password="XXXX" userName="XXXX" />
  </smtp>
 </mailSettings>
</system.net>

I also tried using the IP adress of the server instead of the domain.

In addition to that I set the maildefinition properties on the used web controls:

<MailDefinition From="[email protected]"
 Subject="Your new password">
</MailDefinition>

Once I finish changing or resetting the password, the controls shows the success message. It does not show any errors but the mails are not sent.

I also checked the SMTP log files on the server (it's a MailEnable server) but couldn't even find an attempt to send these messages.

I am using a custom email helper class which manually sends an email using the following settings:

public static void SendEmail(string from, string to, string subject, string body)
{
    SmtpClient mailClient = new SmtpClient(ConfigReader.GetStringValue("MailServer"));
    mailClient.Credentials = new NetworkCredential(ConfigReader.GetStringValue("MailUsername"),
                                                   ConfigReader.GetStringValue("MailPassword"));

    MailMessage mailMessage = new MailMessage(from, to, subject, body);
    mailClient.Send(mailMessage);
}

The values for mailserver, username and password read from the config file are the same as defined in the ASP.NET configuration tool. These mails are delivered successfully.

Any ideas? Thanks in advance!

A: 

I'd put a break point just before mailClient.Send(mailMessage). Set up a wireshark trace running then execute the Send line to see if viewing the network traffic sheds any light.

Martin Smith
I can't: I am not using the helper class along with the membership controls. That was just an example which shows that the smtp server is generally working. The mails sent by this method work as expected.Can I somehow use my own Send method with the membership controls?
SimonW
Well you could still try running Wireshark anyway whilst doing the forgot password procedure. This should show you if it is sending anything to the wrong SMTP server, failing due to credentials, or not sending anything at all for example.
Martin Smith
A: 

Alright, i found a workaround:

I can call my custom EmailHelper class in the passwordRecovery.OnSendingMail event. Strangely the message isn't sent if I set e.Cancel to true AFTER calling my helper (who says it was sent successfully). If I leave e.Cancel = false, everything works.

SimonW