繁体   English   中英

SMTP服务器需要安全连接或客户端未经过身份验证。

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

我在asp中使用“createuserwizard”创建一个表单。这是我的代码。

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

这是我的web.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" />
      </smtp>
    </mailSettings>

然后我选择了以下选项中的Smtp .in ISS设置。

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

现在,当新用户单击“提交”按钮时,它会显示以下错误消息,并且不会发送邮件。

SMTP服务器需要安全连接或客户端未经过身份验证。 服务器响应为:5.7.0必须首先发出STARTTLS命令。 ud8sm21095949igb.4

请帮帮我们

使用enableSsl="true" ,如下所示:

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

服务器需要SSL,因此您需要将其添加到您的配置中:

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

详情请见此处

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);


}

在上面的gv1中是我的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 */
}

您还可以在源代码中编写以下内容

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM