Tuesday, August 5, 2008

Password Recovery Web Control cannot send email Via SSL Mail Servers

I was using lately the Login Controls in a Website I am working on it, and I discovered a bug or you can call it limitation in Password Recovery Web Control. I used to use the Membership provider and Login Controls, but I didn't face this problem before since I was send the email via Non SSL Enabled SMTP server.

Now I was trying to send email using Password Recovery Control via Gmail, I got this error:

The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Must issue a STARTTLS command first. 32sm15616652wfa.13 Password Recovery control read most of the settings from web.config file.

Internally it uses System.Net.Mail to send out email, which does not support reading EnableSSL setting from web.config. This bring us into a situation where Password Recovery control cannot send emails to SSL enabled smtp servers.

This because there is no settings in the Web.Config file for System.Net.Mail (.NET 2.0) that maps to EnableSSL Property of System.Net.Mail.SmtpClient.

Here is the solution for this problem:

1- We will consume the SendingMail Event.
2- This provide us access to the Email Message being sent and also give us option to cancel the sending operation.
3- We Will make a copy of this email message, and create a new instance of System.Net.Mail.SmtpClient
4- This time we have complete access to its properties and we can turn On/Off the EnableSSL setting
5- Lets set EnableSSL to true and send the email message to desired SMTP server.

The below code snippet can do the job:


protected void PasswordRecovery1_SendingMail(object sender, MailMessageEventArgs e)
{
    System.Net.Mail.SmtpClient smtpSender = new System.Net.Mail.SmtpClient("smtp.google.com", 587);
    smtpSender.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
    smtpSender.Credentials = new System.Net.NetworkCredential("username@gmail.com", "password");
    smtpSender.EnableSsl = true;
    smtpSender.Send(e.Message);
    e.Cancel = true;
}

Source: http://www.nilebits.com/blog/2007/01/password-recovery-web-control-can-not-send-email-via-ssl-mail-servers-in-asp-dot-net/

5 comments:

  1. I am geting error it says the target machine actively refused it ???

    ReplyDelete
  2. At recover passwords advise use this tool-get pst password,as how as i remember program is free,tool help to retrieve your password for any of these mail services: Microsoft Mail, Microsoft LDAP Directory, POP3 and IMAP mail server as well as Microsoft Exchange Server,supports all Windows versions, from Windows 98 to Windows Vista. Microsoft Office is supported starting from Microsoft Office 97,permits to find Microsoft Outlook online password and clearing password on Outlook .pst file in a second,clear password for .pst Outlook file and find pst password sorts all characters, including multilingual ones and composes another one, that will be accepted by Microsoft Outlook.

    ReplyDelete
  3. In this situation i advise try next software-find outlook password,as far as i know it is free,also it help to retrieve your password for any of these mail services: Microsoft Mail, Microsoft LDAP Directory, POP3 and IMAP mail server as well as Microsoft Exchange Server,supports all Windows versions, from Windows 98 to Windows Vista. Microsoft Office is supported starting from Microsoft Office 97,permits to find Microsoft Outlook online password and clearing password on Outlook .pst file in a second,clear password for .pst Outlook file and find pst password sorts all characters, including multilingual ones and composes another one, that will be accepted by Microsoft Outlook.

    ReplyDelete
  4. Thank you for your helpful advice.

    ReplyDelete
  5. For execute this action to my mind ther is next utiltiy-recover deleted outlook express messages,it is one of the best in this sphere,program has free status as far as I remember,it can process dbx files regardless of the cause of their damage,supports even batch mode recovering,compatible with Windows NT 4.0, Windows Me, Windows 98, Windows 2000, Windows 2003, Windows XP, Windows Vista and all versions of Outlook Express, currently supported by Microsoft Corporation,recover deleted Outlook Express email, because it is very important to start working with this program and recover deleted messages Outlook Express to prevent further corruption of dbx files,program can restore the data, that was destroyed by viruses, hardware errors and other faults.

    ReplyDelete