【问题标题】:Send email using Outlook.com SMTP使用 Outlook.com SMTP 发送电子邮件
【发布时间】:2013-09-22 15:56:01
【问题描述】:

我正在尝试使用 Outlook.com smtp 支持发送一封自动电子邮件。但是我得到以下异常:

System.Net.Mail.SmtpException: Failure sending mail.  
---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.  
---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host" Exception while sending email.

我的代码:

    public bool SendEmail(MailMessage msg)
    {
        try
        {
            SmtpClient smtpClient = new SmtpClient("smtp-mail.outlook.com")
            {
                UseDefaultCredentials = false,
                DeliveryMethod = SmtpDeliveryMethod.Network,
                Credentials = new NetworkCredential("userAddress", "userPassword"),
                Port = 587,
                EnableSsl = true,
            };
            smtpClient.Send(msg);
            msg.Dispose();
            smtpClient.Dispose();
            return true;
        }
        catch (Exception exp)
        {
            Console.WriteLine(exp.ToString());
            return false;
        }
    }

【问题讨论】:

  • 您是否尝试过使用:smtp.live.com
  • 接收邮件服务器:pop3.live.com 发送邮件服务器 (SMTP):smtp.live.com
  • 是的,我也尝试过使用 smtp.live.com。但是异常仍然被抛出
  • 你试过“smtp.office365.com”吗?
  • 我的帐户只是普通的 Outlook.com 免费帐户。所以我怀疑office365付费smtp是否可行!

标签: c# email smtpclient smtp-auth outlook.com


【解决方案1】:

我知道这是一个非常古老的问题,我什至可能无法提供帮助,但是当我尝试使用 C# 发送电子邮件时遇到了类似的问题。

因此,我使用它来发送电子邮件:

string _sender = "";
        string _password = "";

        SmtpClient client = new SmtpClient("smtp-mail.outlook.com");

        client.Port = 587;
        client.DeliveryMethod = SmtpDeliveryMethod.Network;
        client.UseDefaultCredentials = false;
        System.Net.NetworkCredential credentials =
            new System.Net.NetworkCredential(_sender, _password);
        client.EnableSsl = true;
        client.Credentials = credentials;

        MailMessage message = new MailMessage(_sender, "recipient of email");
        message.Subject = "";
        message.Body = "";
        client.Send(message);

这可能对你不再有用了,但万一有人偶然发现这个问题,至少有一个答案,其中有工作代码作为修复!

【讨论】:

  • 我可以确认此配置今天对我有效。
  • @alex 是“_sender”的电子邮件地址吗?如果没有,你能举个例子说明我应该为此做些什么吗?
  • @user1229458 是的,它是伙伴
  • 截至 2021-03-06 仍然有效
  • @user1229458 MailMessage(string from, string to), MailMessage(MailAddress from, MailAddress to), MailMessage(string from, string to, string subject, string body)
猜你喜欢
  • 1970-01-01
  • 2016-04-17
  • 1970-01-01
  • 1970-01-01
  • 2011-07-30
  • 2015-11-10
  • 2023-03-09
  • 2013-08-16
相关资源
最近更新 更多