gpt4 book ai didi

c# - 无法通过 gmail smtp : keeps waiting for localhost? 发送邮件

转载 作者:太空宇宙 更新时间:2023-11-03 13:31:53 25 4
gpt4 key购买 nike

protected void Button1_Click(object sender, EventArgs e)
{
SmtpClient mail = new SmtpClient();
mail.UseDefaultCredentials = false;
mail.Host="smtp.gmail.com";
mail.Port=465;
mail.Credentials=new NetworkCredential("b.soham1991","*******");
mail.DeliveryMethod = SmtpDeliveryMethod.Network;
mail.EnableSsl = true;

mail.Timeout = 1000000;

mail.Send("b.soham1991@gmail.com", "soham.elf@gmail.com", "Hi", "via gmail");
Response.Write("success!");
}

Response.Write 永远不会执行,最终连接超时。我错过了什么?

最佳答案

我认为您使用了错误的端口。

protected void Button1_Click(object sender, EventArgs e)
{
SmtpClient mail = new SmtpClient();
mail.UseDefaultCredentials = false;
mail.Host="smtp.gmail.com";
mail.Port=587; //new port!
mail.UseDefaultCredentials = false,
mail.Credentials=new NetworkCredential("b.soham1991","*******");
mail.DeliveryMethod = SmtpDeliveryMethod.Network;
mail.EnableSsl = true;

mail.Timeout = 1000000;

mail.Send("b.soham1991@gmail.com", "soham.elf@gmail.com", "Hi", "via gmail");
Response.Write("success!");
}

此外,请务必使用 System.Net.Mail 而不是 System.Web.Mail

引用答案here以获得详细而完善的答案。

关于c# - 无法通过 gmail smtp : keeps waiting for localhost? 发送邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20214030/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com