2016-07-25 136 views
0

這裏郵件沒有發送我想使用Gmail smtp.But我發送郵件時顯示錯誤爲使用Gmail SMTP

SMTP服務器要求安全連接或客戶端未 認證。服務器響應是:5.5.1需要身份驗證

上按鈕單擊insted發送郵件。

HTML

<asp:TextBox ID="txtfrom" runat="server"></asp:TextBox> 
<asp:TextBox ID="txtfrompassword" runat="server"></asp:TextBox> 
<asp:TextBox ID="txtto" runat="server"></asp:TextBox> 
<asp:TextBox ID="txtbody" runat="server"></asp:TextBox> 
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" /> 

代碼背後

protected void Button1_Click(object sender, EventArgs e) 
{ 
    MailMessage msg = new MailMessage(txtfrom.Text,txtto.Text); 
    msg.Body = txtbody.Text; 
    SmtpClient sc = new SmtpClient("smtp.gmail.com", 587); 
    sc.Credentials = new NetworkCredential(txtfrom.Text, txtfrompassword.Text); 
    sc.EnableSsl = true; 
    sc.Send(msg); 
    Response.Write("send"); 
} 
+0

的[發送郵件與網絡憑證在Windows作爲真實的形式不工作(可能的複製http://stackoverflow.com/questions/32475832/mail-sending-with-network-credential-as-true -in-windows-form-not-working) –

回答

0

您可以使用端口25

SmtpClient sc = new SmtpClient("smtp.gmail.com", 25);