这里我想使用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");
}
答案 0 :(得分:0)
您可以使用端口25
SmtpClient sc = new SmtpClient("smtp.gmail.com", 25);
答案 1 :(得分:0)