The SMTP server requires a secure connection or the client was not authenticated.

﹥>﹥吖頭↗ 提交于 2019-12-02 00:09:24

问题


I am creating a form using "createuserwizard" in asp.This is my code.

<asp:CreateUserWizard ID="userwizard" ContinueDestinationPageUrl="~/secretfiles/secret.aspx" runat="server" >
    <MailDefinition BodyFileName="register.txt" Subject="Registration Confirmation" From="amrit.enest@gmail.com" />
    </asp:CreateUserWizard>

This is my web.config file settings.

 <mailSettings>
      <smtp deliveryMethod="Network" from="amrit.enest@gmail.com">
        <network host="smtp.gmail.com" port="25" userName="amrit.enest@gmail.com" password="sending emails's password" />
      </smtp>
    </mailSettings>

Then settled up a Smtp .in ISS settings i selected following options.

->Use localhost(SMTP)
->port=25
->authentication not required 

Now when a new user click submit button ,it gives following error message and mail is not being send.

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. ud8sm21095949igb.4

Please help guys.


回答1:


Use enableSsl="true", like this:

 <mailSettings>
  <smtp deliveryMethod="Network" from="amrit.enest@gmail.com">
    <network enableSsl="true" host="smtp.gmail.com" port="25" userName="amrit.enest@gmail.com" password="sending emails's password" />
  </smtp>
</mailSettings>



回答2:


The server requires SSL, so you need to add this to your config:

<mailSettings>
  <smtp deliveryMethod="Network" from="amrit.enest@gmail.com">
    <network host="smtp.gmail.com" port="25" userName="amrit.enest@gmail.com" 
        password="sending emails's password" enableSsl="true" />
  </smtp>
</mailSettings>

See here for details.




回答3:


protected void Button1_Click(object sender, EventArgs e)
{

    MailMessage mail = new MailMessage();
    MailAddress from = new MailAddress("your mail address@mail.com");
    SmtpClient clientobj = new SmtpClient("smtp.gmail.com");
    mail.From = from;
    mail.To.Add(new MailAddress(" to mail address@gmail.com"));
    mail.Subject = "example gridview";
    mail.Body+="Please check below data <br/><br/>";
    mail.Body += getgridviewdata(gv1);
    mail.IsBodyHtml = true;
    clientobj.Credentials = new System.Net.NetworkCredential("your mailaddress@gmail.com", "your email password");
    clientobj.Port =587;
    clientobj.EnableSsl = true;
  clientobj.Send(mail);


}

in the above gv1 is my gridview id

public string getgridviewdata(GridView gv)
{
    StringBuilder strBuilder = new StringBuilder();
    StringWriter strWriter = new StringWriter(strBuilder);
    HtmlTextWriter htw = new HtmlTextWriter(strWriter);
    gv.RenderControl(htw);
    return strBuilder.ToString();
}
public override void VerifyRenderingInServerForm(Control control)
{
    /* Verifies that the control is rendered */
}

you write the following also in source code

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="example.aspx.cs" Inherits="example" EnableEventValidation="false" %>


来源:https://stackoverflow.com/questions/11795435/the-smtp-server-requires-a-secure-connection-or-the-client-was-not-authenticated

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!