gpt4 book ai didi

c# - 通过 outlook 的 smtp 服务器发送电子邮件

转载 作者:太空宇宙 更新时间:2023-11-03 12:56:51 27 4
gpt4 key购买 nike

我进行了广泛的研究,但没有找到解决我当前问题的有效解决方案。我想使用他们的 SMTP 服务器通过我的 Windows 实时电子邮件发送电子邮件。我收到错误:

“邮箱不可用。服务器响应是:5.7.3 请求的操作已中止;用户未通过身份验证”

我已经尝试使用我的防火墙,尝试在我的帐户中启用 SMTP 设置,以及我在这个网站和其他网站上找到的其他几个解决方案,但没有任何效果。在我的 outlook/windows 帐户的最近事件中,我没有看到 SMTP 访问,只有我当前的登录,即使它说我正在连接。

我不反对使用另一个 SMTP 服务器我正在使用 C#/ASP.NET这是我的代码:

        public static void Email(string name, string recipient, string address, string email, string info)
{
MailMessage mailMsg = new MailMessage();
mailMsg.To.Add(new MailAddress(email));
// From
MailAddress mailAddress = new MailAddress("user@live.com");
mailMsg.From = mailAddress;

//Content
mailMsg.Subject = "Secret Santa";
mailMsg.Body = name + ", your target is " + recipient + ". Please spread the holiday cheer with a soft cap of $20! From an automated mail service";

//SmtpClient
SmtpClient smtpConnection = new SmtpClient("smtp.live.com", 587);
smtpConnection.Credentials = new System.Net.NetworkCredential("user@live.com", "password");
smtpConnection.UseDefaultCredentials = true;

smtpConnection.EnableSsl = true;
smtpConnection.DeliveryMethod = SmtpDeliveryMethod.Network;
smtpConnection.Send(mailMsg);
}

最佳答案

试试下面的代码:

smtpConnection.Credentials = new System.Net.NetworkCredential("user@live.com", "password");

smtpConnection.UseDefaultCredentials = true;

您提供自己的身份验证凭据,因此您必须将 UseDefaultCredentials 设置为 false。否则 SmtpClient 无法进行身份验证,您会收到错误消息。

关于c# - 通过 outlook 的 smtp 服务器发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33597886/

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