【问题标题】:How do I fix "failure in sending email Exception" in sending email in C#?如何在 C# 中发送电子邮件时修复“发送电子邮件异常失败”?
【发布时间】:2020-03-03 18:55:56
【问题描述】:

我正在尝试使用 C# 发送电子邮件 (SMTP),但有一个例外,“发送电子邮件失败”。

我在代码中启用了 SSL 并使用 465 端口(它是开放的)通过 system.net.mail 库将我的电子邮件发送到 Yahoo (smtp.mail.yahoo.com)。

try
{
    string mass = " Hi, this is a compo team email to you for a verification code! Your verification code is: ''" + result + "'' You can enter this code to your compex for go ahead!!!";

    string frommail = "<my mail is here>";
    string tomail = emailtxt.Text;
    string submail = "verification";
    string smtptext = "smtp.mail.yahoo.com";
    string passmail = "<my email password here> ";
    MailMessage mail = new MailMessage(frommail, tomail, submail, mass);
    SmtpClient client = new SmtpClient(smtptext);
    client.Port = 465;
    client.Credentials = new System.Net.NetworkCredential(frommail, passmail);
    client.EnableSsl = true;
    client.Send(mail);
    MessageBox.Show("email sent", "log", MessageBoxButtons.OK);
    /////email
}
catch (Exception exc)
{
    MessageBox.Show(exc.Message);
}

我该如何解决?怎么了?

【问题讨论】:

  • 完整的异常信息是什么?
  • 只是发送邮件失败
  • 您可能想尝试使用端口 587。
  • 试过了。没有更改“发送邮件失败”再次@john

标签: c# smtp smtpclient mailing


【解决方案1】:

您可以做的第一件事是检查您是否可以从您的机器访问 Yahoo SMTP。

最简单的方法是使用 Telnet。

打开一个cmd窗口并运行telnet smtp.mail.yahoo.com 465

通过答案,您将能够找到是防火墙、安全性或其他问题的问题。

【讨论】:

  • 您在哪个版本的 Windows 上尝试过此操作?在 Windows 10 上你会得到 "'telnet' is not known as an internal or external command, operable program or batch file."
  • 可以加instructions on how to enable it吗? Stack Exchange 上可能有一篇关于它的帖子(例如Super User)。
  • Possible command-line way of enabling it, dism /online /Enable-Feature /FeatureName:TelnetClient。但请测试它是否真的有效。
猜你喜欢
  • 2016-07-26
  • 2017-12-08
  • 1970-01-01
  • 2017-02-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多