Problem with sending mail
- In web.config for my web application I added following sections:
<
system.net><
mailSettings><
smtp from=12345@gmail.com deliveryMethod="Network" ><
network host="smtp.gmail.com" port="587" userName=12345@gmail.com password="12345" ></network></
smtp></
mailSettings></
system.net>
Gmail requires SSL so in my code I wrote
SmtpClient
smtpClient = new SmtpClient();smtpClient.EnableSsl =
true;smtpClient.Send(msg);
This code works properly.
Then I need to use PasswordRecovery web control. I can define some properties in MailDefinition but not EnableSsl. Hence when I try use this control with Gmail I receive following error message:
System.Net.Mail.SmtpException: 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 z21sm2134650qbc
How can I fix this problem?
Answers
- Workaround:
<asp:PasswordRecovery ID="PasswordRecovery1" runat="server" OnSendingMail="PasswordRecovery1_SendingMail">
protected void PasswordRecovery1_SendingMail(object sender, MailMessageEventArgs e)
{
SmtpClient smtpClient = new SmtpClient();
smtpClient.EnableSsl = true;
smtpClient.Send(e.Message);
e.Cancel = true;
}
All Replies
- I am not familiar with the PasswordRecovery web control. Can you point me to some documentation for that control? Does it use SmtpClient internnally?
- Yes. This control and probably other new web controls use SmtpClient internally through System.Web.UI.WebControls.LoginUtil.SendPasswordMail internal static method.
IMO, It would be helpful if I and other user will be able to configure SSL requirement for smtp connection in .config file. - Workaround:
<asp:PasswordRecovery ID="PasswordRecovery1" runat="server" OnSendingMail="PasswordRecovery1_SendingMail">
protected void PasswordRecovery1_SendingMail(object sender, MailMessageEventArgs e)
{
SmtpClient smtpClient = new SmtpClient();
smtpClient.EnableSsl = true;
smtpClient.Send(e.Message);
e.Cancel = true;
}
after more than 1 year this looks like the best workaround I did found !!!!
Can someone tell me if it is now possible to EnableSsl in web.config ?
ciao,
marco
- I have exactly the same problem.
Nobody knows the solution? Yeah I had the same problem as you. I've searched everywhere to find a way to enable SSL in web.config but couldn't find an answer.
Doesn't matter now, the solution in this forum is good enough for me!!

I have added this as a suggestion on Microsoft connect:
https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=281277


