【问题标题】:Mail not sent using gmail smtp邮件未使用 gmail smtp 发送
【发布时间】:2016-07-25 10:01:25
【问题描述】:

这里我想使用 gmail smtp 发送邮件。但是我显示错误

SMTP 服务器需要安全连接,或者客户端没有 认证。服务器响应为:5.5.1 需要身份验证

点击按钮发送邮件。

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

【问题讨论】:

标签: c# asp.net email


【解决方案1】:

开启此选项

你可以使用STMP发送邮件

https://www.google.com/settings/security/lesssecureapps

【讨论】:

    【解决方案2】:

    您可以使用端口 25

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

    【讨论】:

      猜你喜欢
      • 2017-11-14
      • 2021-06-17
      • 2015-09-28
      • 1970-01-01
      • 2018-02-11
      • 2017-11-04
      • 1970-01-01
      • 2016-10-25
      相关资源
      最近更新 更多