Password recovery web control can not send email via SSL mail servers in ASP.NET

Password recovery web control

Password recovery web control can not send email via SSL mail servers in ASP.NET

We were using lately the login controls for ASP.NET in a website we are working on it. We discovered a bug or we can call it limitation in the password recovery web control. We used to use the membership provider and login controls, but we did not face this problem before since we were sending the email via non SSL enabled SMTP server.

Now when we try to send email using password recovery control via Gmail, we get 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 emails, which does not support reading EnableSSL setting from web.config. This bring us into a situation where password recovery control can not send emails to SSL enabled smtp servers.

This because there is no settings in the web.config file for System.Net.Mail that maps to EnableSSL property of System.Net.Mail.SmtpClient.

Please find below the solution for this problem:

  1. We will consume the SendingMail event.
  2. This would 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. Now 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 will do the job:

using System.Web.UI.WebControls;
namespace NB.BlogCode
{
    public class RecoverPassword
    {
        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", "password");
            smtpSender.EnableSsl = true;
            smtpSender.Send(e.Message);
            e.Cancel = true;
        }
    }
}

 

Share this post

Comments (5)

  • TmanIs Reply

    I am getting error it says the target machine actively refused it ???

    February 1, 2007 at 11:31 AM
    • Amr Saafan

      This error message indicates that the Source or Destination system blocked the connection. This may be due to firewall or web server settings. In some cases, an IP restriction may be in place, so I recommend checking access from outside your intranet.

      February 2, 2007 at 4:40 PM
  • Alex Reply

    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.

    February 3, 2007 at 7:21 PM
  • Anonymous Reply

    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.

    February 4, 2009 at 2:12 PM
  • Alex Reply

    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.

    February 5, 2009 at 4:31 PM

Leave a Reply

Your email address will not be published. Required fields are marked *