在ASP中发送电子邮件.净c#
本文关键字:电子邮件 ASP | 更新日期: 2023-09-27 18:08:18
我正在为我的网站的访问者创建一个联系页面,给我发送电子邮件(在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;
}
Thanks in advance
如下所示http://forums.asp.net/t/1622198.aspx?Syntactically+invalid+EHLO+argument+s+emailing
如果您的电子邮件有被拒绝的EHLO或HELO的问题,由语法上无效的参数引起的
1。主机名可能包含下划线(_)。
2。这不是标准的做法,用_作为你的域
3。例如takizo_mail.takizo.com
4。大多数邮件服务器拒绝带有下划线的主机名。
5。
确保服务器名称中只有拉丁字符,并且没有下划线等特殊符号
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);