gpt4 book ai didi

ssl - Asp.netSendEmail SMTP 服务器要求安全连接或客户端未通过身份验证

转载 作者:太空宇宙 更新时间:2023-11-03 14:47:41 24 4
gpt4 key购买 nike

我正在使用 google smtp 发送电子邮件。该代码在我的本地机器中正常工作。但是在生产服务器上,我收到的错误消息是 SendEmail The SMTP server requires a secure connection or client was not authenticated。服务器响应是:5.5.1 需要身份验证。了解更多信息

我试过了,client.UseDefaultCredentials = true;将其设置为 false 但它不起作用。

最佳答案

尝试使用此代码通过 Google 发送邮件

            MailMessage oMail = new MailMessage();
SmtpClient smtpClient = new SmtpClient();
string FromMailID = "yourgmailid@gmail.com";
string UserName = "GmailUsername";
string Password = "GmailPassword";

MailAddress fromAddress = new MailAddress(FromMailID);
if (FilePath != "")//If attached file otherwise comment
{
Attachment PDFfile = new Attachment(FilePath);
oMail.Attachments.Add(PDFfile);
}
oMail.From = fromAddress;
oMail.To.Add(ToMailID);
oMail.Subject = Subject;
oMail.IsBodyHtml = true;
oMail.Body = Mailcontent.ToString();
smtpClient.Host = "smtp.gmail.com"; // We use gmail as our smtp client
smtpClient.Port = 25;//localhost
smtpClient.UseDefaultCredentials = false;
smtpClient.EnableSsl = true;
smtpClient.UseDefaultCredentials = true;
smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpClient.Credentials = new System.Net.NetworkCredential(UserName, Password);

smtpClient.Send(oMail);

关于ssl - Asp.netSendEmail SMTP 服务器要求安全连接或客户端未通过身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37475581/

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