gpt4 book ai didi

C# - 发送邮件失败

转载 作者:行者123 更新时间:2023-11-30 14:33:47 25 4
gpt4 key购买 nike

当我部署这段代码时,它在我的本地机器上运行良好。它给出了 Failure sending mail 错误.. 请帮助...

MailAddress addrsTo = new MailAddress(toEmail);
MailAddress addrsFrom = new MailAddress("XXX@XXX.com", "XXX Title");

MailMessage mailmsg = new MailMessage(addrsFrom, addrsTo);
mailmsg.Subject = mailSbjct;

mailmsg.Body = "XXX Body";

SmtpClient smtp = new SmtpClient("mail.XXX.com");
smtp.EnableSsl = false;
smtp.Port = 26;
smtp.Credentials = new NetworkCredential("XXX@XXX.com", "XXXXXXX");

try {
smtp.Send(mailmsg);
} catch (Exception exc) {
throw new XXXException(1234, "---" + exc.Message);

}

最佳答案

如果您使用的是gmail,您可以试试这个:

 MailMessage mail = new MailMessage();
mail.Subject = "Your Subject";
mail.From = new MailAddress("senderMailAddress");
mail.To.Add("ReceiverMailAddress");
mail.Body = "Hello! your mail content goes here...";
mail.IsBodyHtml = true;

SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
smtp.EnableSsl = true;
NetworkCredential netCre = new NetworkCredential("SenderMailAddress","SenderPassword" );
smtp.Credentials = netCre;

try
{
smtp.Send(mail);
}
catch (Exception ex)
{
}

关于C# - 发送邮件失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15541045/

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