发送邮件的ASP.NET错误

时间:2012-02-20 17:39:16

标签: asp.net sendmail

这是内联网应用程序,我正在使用公司的邮件来发送电子邮件。它在我拥有的其他应用程序中工作正常,但在这个应用程序中没有,一切都是一样的。 我在尝试发送邮件时收到“System.Net.Mail.SmtpException:参数或参数中的语法错误。服务器响应是:5.5.2 MAIL FROM语法错误”。 我就是这样设置的:

MailMessage mm = new MailMessage();
    mm.From = new MailAddress("NoReply@AMS_Redirection.company.org");
    mm.To.Add(new MailAddress("my_emailaddress@company.org"));
    mm.Subject = "AMS Redirection Error";
    mm.Priority = MailPriority.Normal;
    mm.IsBodyHtml = true;
    mm.Body = "some html stuff here";

    SmtpClient sc = new SmtpClient("mailrelay.company.org");
    sc.Credentials = new NetworkCredential();

    try
    {
        sc.Send(mm);
    }
    catch (SmtpException smtpEx)
    {
        //A problem occurred when sending the email message
        string sScript = string.Format("alert(\"There was a problem in sending the email: {0}\");", smtpEx.Message.Replace("\r\n", " "));
        ClientScript.RegisterStartupScript(this.GetType(), "SMTP Error", sScript, true);
    }

我可以成功ping邮件中继。

2 个答案:

答案 0 :(得分:0)

尝试将'from'地址设置为您知道错误的地址。当我的SMTP转发服务拒绝“发件人”地址时,我收到此异常。如果它仍然以同样的方式失败,你知道问题出在继电器的配置中。

答案 1 :(得分:0)

您检查SMTP服务器的smtp端口是否为标准端口?否则你必须明确设置它。

相关问题