公司网站是用2.0写的,以前服务器在国内、在香港,用的都是win2003+IIS6,都能正常发送邮件,最近买了个美国服务器,自带配置是win2008和IIS7,3.0的.net,原来的代码发送邮件失败: MailMessage mail = new MailMessage();
string sysEmail, sysEmailPassword, sysEmailSMTP, sysEmailPort, email = "[email protected]";
sysEmail = "[email protected]";
sysEmailPassword = "xxxx";
sysEmailSMTP = "smtp.xxx.cn";
sysEmailPort = "25";
mail.From = new MailAddress(sysEmail);
mail.To.Add(email);
mail.Subject = "测试邮件";
mail.Body = "<h4>测试邮件</h4>电子邮件测试,时间:" + DateTime.Now.ToLongTimeString();
mail.IsBodyHtml = true;
System.Net.Mail.SmtpClient sc = new SmtpClient(sysEmailSMTP, int.Parse(sysEmailPort));
sc.UseDefaultCredentials = true;
sc.Credentials = new System.Net.NetworkCredential(sysEmail, sysEmailPassword);
sc.DeliveryMethod = SmtpDeliveryMethod.Network;
sc.Send(mail);
Result = "<a>邮件已发送到" + email + ",请注意查收。</a>";提示“A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond xxx.xxx.xxx.xxx:25”
发送失败,我检查了下,服务器没装杀毒软件,没防火墙,25端口也打开了,于是安装了SMTP服务,把原代码做了下修改 sc.DeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory;
sc.PickupDirectoryLocation = @"C:\Inetpub\mailroot\Pickup";这下就不报错了,但是邮件在\mailroot\Queue\蹲了半天,就到\mailroot\Badmail\去了,查看.BDR
“Unable to deliver this message because the follow error was encountered: "This message is a delivery status notification that cannot be delivered.".
The specific error code was 0xC00402C7.
The message sender was <>.
The message was intended for the following recipients.
[email protected]
”改用Jmail算了 jmail.Message Jmail = new jmail.Message();
String Subject = "测试邮件";
String body = "<h4>测试邮件</h4>电子邮件测试,时间:";
String FromEmail = "[email protected]";
String ToEmail = "[email protected]";
Jmail.AddRecipient(ToEmail, "", "");
Jmail.From = FromEmail;
Jmail.MailServerUserName = "[email protected]";
Jmail.MailServerPassWord = "xxxxxx";
Jmail.Subject = Subject;
Jmail.Body = body + DateTime.Now.ToShortTimeString();
Jmail.ContentType = "text/html;";
Jmail.Send("smtp.xxx.cn", false);
Jmail.Close();
Jmail组件已经注册过了,在本地测试可以发送,但是在服务器还是不行,提示“The message was undeliverable. All servers failed to receive the message ”求救啊!
string sysEmail, sysEmailPassword, sysEmailSMTP, sysEmailPort, email = "[email protected]";
sysEmail = "[email protected]";
sysEmailPassword = "xxxx";
sysEmailSMTP = "smtp.xxx.cn";
sysEmailPort = "25";
mail.From = new MailAddress(sysEmail);
mail.To.Add(email);
mail.Subject = "测试邮件";
mail.Body = "<h4>测试邮件</h4>电子邮件测试,时间:" + DateTime.Now.ToLongTimeString();
mail.IsBodyHtml = true;
System.Net.Mail.SmtpClient sc = new SmtpClient(sysEmailSMTP, int.Parse(sysEmailPort));
sc.UseDefaultCredentials = true;
sc.Credentials = new System.Net.NetworkCredential(sysEmail, sysEmailPassword);
sc.DeliveryMethod = SmtpDeliveryMethod.Network;
sc.Send(mail);
Result = "<a>邮件已发送到" + email + ",请注意查收。</a>";提示“A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond xxx.xxx.xxx.xxx:25”
发送失败,我检查了下,服务器没装杀毒软件,没防火墙,25端口也打开了,于是安装了SMTP服务,把原代码做了下修改 sc.DeliveryMethod = SmtpDeliveryMethod.SpecifiedPickupDirectory;
sc.PickupDirectoryLocation = @"C:\Inetpub\mailroot\Pickup";这下就不报错了,但是邮件在\mailroot\Queue\蹲了半天,就到\mailroot\Badmail\去了,查看.BDR
“Unable to deliver this message because the follow error was encountered: "This message is a delivery status notification that cannot be delivered.".
The specific error code was 0xC00402C7.
The message sender was <>.
The message was intended for the following recipients.
[email protected]
”改用Jmail算了 jmail.Message Jmail = new jmail.Message();
String Subject = "测试邮件";
String body = "<h4>测试邮件</h4>电子邮件测试,时间:";
String FromEmail = "[email protected]";
String ToEmail = "[email protected]";
Jmail.AddRecipient(ToEmail, "", "");
Jmail.From = FromEmail;
Jmail.MailServerUserName = "[email protected]";
Jmail.MailServerPassWord = "xxxxxx";
Jmail.Subject = Subject;
Jmail.Body = body + DateTime.Now.ToShortTimeString();
Jmail.ContentType = "text/html;";
Jmail.Send("smtp.xxx.cn", false);
Jmail.Close();
Jmail组件已经注册过了,在本地测试可以发送,但是在服务器还是不行,提示“The message was undeliverable. All servers failed to receive the message ”求救啊!
解决方案 »
- TreeView 显示找不到图片
- 头像上传问题,怎样将图片上传到另一个站点下面??
- 关于web应用程序界面设计的问题
- 帮忙转换RSS的编码为GBK阿。。
- (sender as object,E as eventargs)这两个参数代表什么意思?
- 如何在只有.NET Framework2.0环境的机器上运行.NET Framework1.1下编写的网站。
- 帮忙排错
- 急死人啦!一周之内发了三个贴,也没能结贴。ASP.NET数据更新、删除、插入都报下面的错,将.MDB权限设置成Everyone完全控制也不行,到底
- 大家来讨论一个关于分级、分权限的算法啊
- 自动生成WORD或者excel的思路和代码
- C# linq to sql
- 抢救!!抢救!!!
如果你的服务器不支持SMTP或者你的账号不能使用SMTP服务,那么就无法发送。
注意....
QQ邮箱默认情况下POP和SMTP服务是关闭的,进入您的QQ邮箱——》【设置】——》【账户】——》【POP3/IMAP/SMTP服务】,进行相关设置。