這是內部網應用程序,我正在使用公司的郵件發送電子郵件。它可以在我有的其他應用程序中正常工作,但不是在這個應用程序中,一切都一樣。 嘗試發送郵件時,出現「System.Net.Mail.SmtpException:參數或參數中的語法錯誤,服務器響應爲:5.5.2 MAIL FROM語法錯誤」。 這是我如何設置它:發送郵件的ASP.NET錯誤
MailMessage mm = new MailMessage();
mm.From = new MailAddress("[email protected]_Redirection.company.org");
mm.To.Add(new MailAddress("[email protected]"));
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通郵件中繼。
謝謝你的快速回復,Enrico和@ n8wrl。我在另一個使用完全相同的代碼並且工作正常的Intranet應用程序中對此進行了測試。所以,我不確定這是否是真正的郵件問題。 「發件人:」是一個虛假的電子郵件地址,只是爲了讓用戶知道不要回復它並在其他應用程序中設置相同的方式。 – NoBullMan 2012-02-20 18:07:10
@ n8wrk和恩里科,我發現這個問題,它似乎真的很幼稚;我不知道這是否適用於所有電子郵件地址,或者它只是我們的郵件中繼,但是當我將AMS_Redirection.company.org上的「From:」地址更改爲AMSRedir.company.org時,它工作正常。我擺脫了下劃線並縮短了一下! – NoBullMan 2012-02-20 18:29:55