邮件无法发送到 SMTP 服务器。传输错误代码为 0x80040217。服务器响应为 not available
using System;using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using CDO;
using System.Web.Mail;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//12976095
}
/// <summary>
/// 发送邮件
/// </summary>
/// <param name="email">要发送的邮件地址</param>
/// <param name="bodys">邮件内容</param>
/// <param name="Titles">邮件标题</param>
public void Emailto(string email, string bodys, string Titles)
{
//smtp服务器
string SmtpServer = ConfigurationManager.AppSettings["RandVServer"];
//smtp验证所需用户名
string Username = ConfigurationManager.AppSettings["RandVSender"];
//密码
string UserPass = ConfigurationManager.AppSettings["RandVPass"];
//配置
CDO.Configuration conf = new ConfigurationClass();
conf.Fields[CdoConfiguration.cdoSendUsingMethod].Value = CdoSendUsing.cdoSendUsingPort;
conf.Fields[CdoConfiguration.cdoSMTPServer].Value = SmtpServer;
conf.Fields[CdoConfiguration.cdoSMTPAuthenticate].Value = CdoProtocolsAuthentication.cdoBasic;
conf.Fields[CdoConfiguration.cdoSendUserName].Value = Username;
conf.Fields[CdoConfiguration.cdoSendPassword].Value = UserPass;
conf.Fields[CdoConfiguration.cdoSMTPServerPort].Value = "25";
conf.Fields.Update();
//邮件发送
MessageClass msg = new MessageClass();
msg.Configuration = conf;
msg.To = email;
msg.From = Username;
msg.Subject = Titles;
msg.HTMLBody = "<html><body>" + bodys + "<br>" + "<a target='_blank' href='Http://www.randv.com'>" + "欢迎您加入共合网(http://www.randv.com)" + "</a>" + "</body></html>";
msg.BodyPart.Charset = "gb2312";
msg.HTMLBodyPart.Charset = "gb2312";
msg.Send();
msg = null;
}
protected void send_Click(object sender, EventArgs e)
{
string body = mailbody.Text.Trim();
string mail = "kjun163@163.com";
string title = "好啊";
Emailto(mail,body,title);
}
}
--------------------编程问答-------------------- 我顶 顶顶顶顶 --------------------编程问答-------------------- 我试了很多方法都发不过去,此方法行吗?我都没信心再试了 --------------------编程问答-------------------- 我还是试了一次,不行,没有using cdo命名空间啊 --------------------编程问答-------------------- 我也快不行了,被这东西搞得 --------------------编程问答-------------------- 唉 每次试了各种方法都失败! --------------------编程问答-------------------- - - 安得维 --------------------编程问答-------------------- 一样纠结中 --------------------编程问答-------------------- 参考:http://www.cnblogs.com/insus/articles/1689279.html --------------------编程问答-------------------- 1、dns解析是不是对
2、目前大多数邮件服务器不接受动态ip
3、CDO测试下来对安全认证支持不好 --------------------编程问答-------------------- 还是用System.Net.Mail吧,我也试了很多次System.Web.Mail,还是不行。
不知道是不是System.Web.Mail过时的原因。
补充:.NET技术 , ASP.NET