【问题标题】:Failure sending e-mail in asp.net在 asp.net 中发送电子邮件失败
【发布时间】:2014-08-29 05:46:33
【问题描述】:

这是我的代码。我知道这是一个重复的问题,但我访问了 staqckoverflow 和 codeproject 中的所有链接,但仍然无法得到答案。

try
    {
        MailMessage mailmessage = new MailMessage();
        mailmessage.To.Add("xxx.com");
        mailmessage.From = new MailAddress("xxx.com");
        mailmessage.Subject = "Transaction sent for Verification ";
        mailmessage.Body = "Hello world,\n\nThis is an ASP.NET test e-mail!";
        SmtpClient smtpClient = new SmtpClient(ConfigurationSettings.AppSettings["SmtpAdd"].ToString());
        smtpClient.Send(mailmessage);
        ClientScript.RegisterStartupScript(this.GetType(), "mailalert", "alert('" + "Mail sent for verification" + "');", true);
    }
    catch(Exception ex)
    {
        //Response.Write("Could not send E-mail- error: " + ex.Message);
        ClientScript.RegisterStartupScript(this.GetType(), "mailfailure", "alert('" + ex.Message + "');", true);
    }

【问题讨论】:

  • 请发布错误跟踪。
  • 错误信息是发送邮件失败。我的意思是异常消息
  • 请检查内部异常。有很多潜在的原因(错误的 smtp、丢失的凭据等)
  • 在 smtp 地址的某行显示 Java 异常错误。
  • 正如克劳迪奥所说,请发布 InnerException 的实际文本。知道它在说什么真的很有帮助,“java”异常将是一个非常奇怪的异常。

标签: c# asp.net email webforms


【解决方案1】:

这对你有帮助

MailMessage msg = new MailMessage();
        msg.From = new MailAddress(email);
        msg.To.Add(new MailAddress("To_address"));
        msg.Subject = "You have a WebMail!!";
        msg.IsBodyHtml = true;
        msg.Body = "Message";
        SmtpClient smtp = new SmtpClient();
        smtp.Credentials = new NetworkCredential("your mail address", "your password");
        smtp.Host = "host name";
        smtp.Port = "host number";
        smtp.EnableSsl = false;
        smtp.Send(msg);

【讨论】:

    猜你喜欢
    • 2017-12-08
    • 1970-01-01
    • 2019-07-19
    • 2017-02-09
    • 2016-07-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多