[英]Send email in ASP.NET C#
我正在為我的網站的訪問者創建一個聯系頁面,以向我發送電子郵件(使用C#)。 嘗試時,出現關於EHLO參數的錯誤。 這是我的代碼:
我得到了錯誤:
服務器響應為:語法上無效的EHLO參數。
請幫忙
try
{
MailMessage _email = new MailMessage();
String MessageString = "";
MessageString = "<br>";
MessageString += "<b>Message from " + champNom.Value + "</b><br /><br />";
MessageString += "<br/><br/>";
MessageString += champMail.Text;
_email.Subject = "Mail from " + champNom.Value + " (Email adress: " + champEmail.Text + ")";
_email.From = new System.Net.Mail.MailAddress(System.Configuration.ConfigurationManager.AppSettings["SenderForEmail"].ToString(), "MyName");
_email.To.Add(new System.Net.Mail.MailAddress(System.Configuration.ConfigurationManager.AppSettings["AdminForEmail"].ToString(), "MyName"));
if (chkCCMyself.Checked) {
_email.CC.Add(new System.Net.Mail.MailAddress(champEmail.Text, champNom.Value));
}
_email.Body = MessageString;
_email.IsBodyHtml = true;
System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient();
smtp.EnableSsl = false;
//smtp.UseDefaultCredentials = true;
//smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.Host = System.Configuration.ConfigurationManager.AppSettings["HostForEmail"].ToString();
smtp.Port = 587;
smtp.Credentials = new System.Net.NetworkCredential(System.Configuration.ConfigurationManager.AppSettings["SenderForEmail"].ToString(), System.Configuration.ConfigurationManager.AppSettings["SenderPswdForEmail"].ToString());
smtp.Send(_email);
Page.RegisterStartupScript("UserMsg", "<script>alert('Mail envoyé avec succès...');if(alert){ window.location='contact.aspx';}</script>");
}catch(Exception err){
champMail.Text += Environment.NewLine + err.Message;
}
提前致謝
如此處所述http://forums.asp.net/t/1622198.aspx?語法上+無效+ EHLO + argument + s + emailing
如果通過電子郵件發送因語法無效的參數而導致的EHLO或HELO拒絕問題。
1.可能的主機名包含下划線(_)。
2.這不是標准做法,您的網域使用_
3.例如takizo_mail.takizo.com
4.大多數郵件服務器拒絕帶下划線的主機名。
5.Possibility是Windows管理員
確保服務器名稱中僅包含拉丁字符,並且不包含下划線等特殊符號。
MailMessage msg = new MailMessage("from@a.com", "To@y.com");
msg.Subject = "Intraday";
msg.Sender = new MailAddress("sender@y.com");
msg.IsBodyHtml = false; //to preserve line breaks and to avoid the need for <br>s
msg.Body = "Body";
SmtpClient client = new SmtpClient("Server");
client.Send(msg);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.