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

Sending an email through outlook's smtp server

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

"Mailbox unavailable. The server response was: 5.7.3 Requested action aborted; user not authenticated"

我试过使用我的防火墙,尝试在我的帐户中启用 SMTP 设置,以及我在这个网站和其他网站上找到的其他几个解决方案,但没有任何效果。在我的 outlook/windows 帐户最近的 activity 中,我没有看到 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 ! 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 无法进行身份验证,您会收到错误消息。