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