【问题标题】:SMTP Live.com "Failure sending mail"SMTP Live.com“发送邮件失败”
【发布时间】:2014-10-26 10:34:26
【问题描述】:

这些代码有什么问题?它总是抛出一个异常“{”发送邮件失败。“}”!我不知道为什么。请帮我。

编辑:内部异常:{“无法连接到远程服务器”}

        string smtpAddress = "smtp.live.com";
        int portNumber = 587;
        bool enableSSL = true;

        string emailFrom = "myemail@live.com";
        string password = "myPassword";
        string emailTo = "otherEmail@live.com";
        string subject = "Hello";
        string body = "Hello, I'm just writing this to say Hi!";

        using (MailMessage mail = new MailMessage())
        {
            mail.From = new MailAddress(emailFrom);
            mail.To.Add(emailTo);
            mail.Subject = subject;
            mail.Body = body;
            mail.IsBodyHtml = false;

            using (SmtpClient smtp = new SmtpClient(smtpAddress, portNumber))
            {
                smtp.Credentials = new NetworkCredential(emailFrom, password);
                smtp.EnableSsl = enableSSL;
                smtp.Send(mail);
            }
        }

【问题讨论】:

  • 检查是否有更多信息的内部异常
  • 内部异常:{“无法连接到远程服务器”} Internet 工作正常。
  • {"连接尝试失败,因为连接的一方在一段时间后没有正确响应,或者建立连接失败,因为连接的主机没有响应 myIPAdresse"}
  • 与您的代码无关的东西...防火墙?尝试远程登录。

标签: c# email smtp send


【解决方案1】:

这样发送邮件时去掉 using 关键字:

来自:

using (SmtpClient smtpClient = new SmtpClient())

到:

SmtpClient smtpClient = new SmtpClient();

删除大括号也是这样的:

smtp.Credentials = new NetworkCredential(emailFrom, password);
smtp.EnableSsl = enableSSL;
smtp.Send(mail);

【讨论】:

  • 同样的错误:无法连接到服务器!
猜你喜欢
  • 2015-08-27
  • 1970-01-01
  • 2017-02-09
  • 2015-11-20
  • 2023-03-10
  • 2012-11-10
  • 2013-09-01
  • 2011-12-10
  • 2019-03-01
相关资源
最近更新 更多