gpt4 book ai didi

c# - 使用 c# SmtpClient 的 Gmail SMTP 失败

转载 作者:行者123 更新时间:2023-12-04 22:36:20 28 4
gpt4 key购买 nike

我们的应用程序可以通过 SmtpClient 发送电子邮件。我们的一位客户试图通过使用他的 gmail 帐户来执行此操作,但失败导致超时。但是,从我们的测试实验室来看,它工作得很好(使用另一个 gmail 帐户)。
this is the trace we got from our customer
在跟踪中,我可以看到服务器没有用证书、服务器 key 交换、服务器问候完成来回答。我想知道这可能是什么原因?
我还在跟踪中注意到,客户正在使用 TLSv1,所以我尝试在 Windows7 系统上复制错误,但它仍然对我有用。

    oSmtp = new SmtpClient(this.host, this.port);
oSmtp.DeliveryMethod = SmtpDeliveryMethod.Network;
oSmtp.EnableSsl = ssl;
NetworkCredential oCredential = new NetworkCredential(this.userName, this.password);
oSmtp.Credentials = oCredential;
oSmtp.SendCompleted += new SendCompletedEventHandler(SendCompletedCallback);
string userState = null;
oSmtp.SendAsync(oMsg, userState);
就代码而言,enableSsl 为真,端口为 587,我们还指示我们的客户检查他的 gmail 帐户并允许不太安全的应用程序。
我们会询问客户更具体的细节,并尝试在我们的应用程序中添加更多的痕迹,但我想知道是否有任何东西可以阻止服务器用证书回答,...
检查痕迹显示客户 Client Hello 和我们的测试 Client Hello 之间没有显着差异。
谢谢!

最佳答案

这是我几天前使用的工作示例:

            string fromAddress = "fromaddress@gmail.com";
var toAddress = new MailAddress("fake@email.com", "To person");
const string fromPassword = "pass";
const string subject = "test";
const string body = "Hey now!!";

using (MailMessage mail = new MailMessage())
{
mail.From = new MailAddress(fromAddress);
mail.To.Add(toAddress);
mail.Subject = subject;
mail.Body = body;
mail.IsBodyHtml = true;
//mail.Attachments.Add(new Attachment("C:\\file.zip"));

using (SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587))
{
smtp.UseDefaultCredentials = false;
smtp.Credentials = new NetworkCredential(fromAddress, fromPassword);
smtp.EnableSsl = true;
smtp.Send(mail);
}
}
还要确保启用 Less secure app access 对于您用来发送数据的 gmail:

关于c# - 使用 c# SmtpClient 的 Gmail SMTP 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63842428/

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