【发布时间】:2018-11-11 04:21:47
【问题描述】:
我正在尝试发送附有 pdf 的电子邮件,我的 pdf 是字节数组。当我尝试发送邮件(没有 pdf)时,它会显示
消息 = SMTP 服务器需要安全连接或客户端未通过身份验证。服务器响应为:5.5.1 需要身份验证。了解更多信息,请访问
我的代码是`string senderEmail = System.Configuration.ConfigurationManager.AppSettings["SenderEmail"].ToString(); string senderPassword = System.Configuration.ConfigurationManager.AppSettings["SenderPassword"].ToString();
SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
client.EnableSsl = true;
client.Timeout = 100000;
client.DeliveryMethod = SmtpDeliveryMethod.Network;
client.UseDefaultCredentials = false;
client.Credentials = new NetworkCredential(senderEmail, senderPassword);
MailMessage mailMassege = new MailMessage(senderEmail, toEmail, subject, body);
mailMassege.IsBodyHtml = true;
mailMassege.BodyEncoding = Encoding.UTF8;
client.Send(mailMassege);`
我的 pdf 在字节数组中
byte[] applicationPDFData = actionResult.BuildPdf(ControllerContext);
System.IO.File.WriteAllBytes(filePath + "/hello.pdf", applicationPDFData);
我想用这个 pdf 发送邮件。 提前谢谢
【问题讨论】:
-
代码相同,我也关闭了两步验证但同样的错误
-
这只是猜测,但在您的 google 帐户上,less secure apps 是否启用?
-
我可以看到错误与身份验证有关。尝试使用端口 465。您可以在此处找到更多详细信息:support.google.com/a/answer/176600?hl=en 另外,它会发送不带附件的电子邮件吗?
标签: c# asp.net asp.net-mvc smtp