Ask a questionAsk a question
 

AnswerProblem with sending mail

  • Friday, December 09, 2005 2:54 PMshatokhin Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    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

  • Wednesday, December 14, 2005 2:08 PMshatokhin Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    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

  • Friday, December 09, 2005 5:23 PMJonCole - MSFTModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I am not familiar with the PasswordRecovery web control.  Can you point me to some documentation for that control?  Does it use SmtpClient internnally?
  • Monday, December 12, 2005 9:31 AMshatokhin Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    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.
  • Wednesday, December 14, 2005 2:08 PMshatokhin Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    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;

    }

  • Sunday, March 18, 2007 2:01 PMzagolin Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    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

     

  • Tuesday, April 24, 2007 11:13 PMMario Ruiz Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I have exactly the same problem.
    Nobody knows the solution?
  • Sunday, April 29, 2007 12:30 PMBill _Australia-Melbourne_ Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    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!! 

  • Monday, June 04, 2007 7:13 PMJames Crowley Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    I have added this as a suggestion on Microsoft connect:

     

    https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=281277