小编And*_*ndy的帖子

使用Outlook.com SMTP发送电子邮件

我正在尝试使用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.
Run Code Online (Sandbox Code Playgroud)

我的代码:

    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;
        } …
Run Code Online (Sandbox Code Playgroud)

c# email smtpclient smtp-auth outlook.com

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

c# ×1

email ×1

outlook.com ×1

smtp-auth ×1

smtpclient ×1