日期:2014-05-17  浏览次数:20587 次

asp.net发送电子邮件问题?????
MailMessage mailObj = new MailMessage();
  mailObj.From = new MailAddress("lz6e804@lisco.com.cn");//发信人地址
  mailObj.To.Add("haoyuning@foxmail.com");//收信地址
  mailObj.CC.Add("haoyuning@foxmail.com");//抄送地址
  mailObj.Subject = "这里填写邮件标题2222222";//邮件标题
  mailObj.Body = "这里是正文的内容2222222222222222222222";
  //html格式的邮件
  mailObj.IsBodyHtml = true;
  ////设置为高级优先权(可设可不设)
  //mailObj.Priority = MailPriority.High;
  //使用SmtpMail对象发送邮件
  SmtpClient smtp = new SmtpClient("123.156.97.148");//服务器的地址
  smtp.Send(mailObj);//发送邮件

运行以上代码(报错):由于目标机器积极拒绝,无法连接。 123.156.97.148:25 
怎么解决?????


------解决方案--------------------
是在什么环境下出现这种情况的,我之前遇到过类似的情况,但是是本机OK,放到服务器上就不行,原因是防火墙把25的端口关了
------解决方案--------------------
/// <summary>
/// 发送邮件
/// </summary>
/// <param name="subject">邮件标题</param>
/// <param name="content">邮件内容</param>
/// <param name="tomail">接收邮件地址</param>
protected void SendMail(string subject, string content, string tomail)
{
MailMessage objMailMessage;

// 创建邮件消息 
objMailMessage = new MailMessage();
objMailMessage.From = rwWebConfig.readConfigValue("formemail");
objMailMessage.To = tomail;
objMailMessage.Subject = subject; 
objMailMessage.BodyFormat = MailFormat.Html;
objMailMessage.Body = content;

objMailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
//用户名 
objMailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", rwWebConfig.readConfigValue("username"));
//密码 
objMailMessage.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", rwWebConfig.readConfigValue("password"));

//SMTP地址 
SmtpMail.SmtpServer = rwWebConfig.readConfigValue("smtp");
//开始发送邮件 
SmtpMail.Send(objMailMessage);
}
------解决方案--------------------
参考这里
http://www.heycoder.com/noteinfo8.aspx
------解决方案--------------------
1.QQ: 

System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
msg.To.Add("xxx@xxx.com");
msg.From = new MailAddress("xxxxx@qq.com", "handyzhu", System.Text.Encoding.UTF8);
msg.Subject = "标题";
msg.Body = "测试";
SmtpClient client = new SmtpClient();
client.Credentials = new System.Net.NetworkCredential("164206528@qq.com","********");
client.Port = 25;
client.Host = "smtp.qq.com";
object userState = msg;

client.Send(msg);

 

2.163

 

public static string CreateTimeoutTestMessage(string server) 

string Success = "发送成功"; 
try 

string _to = "xxxx@qq.com"; 
string _from = "xxx@163.com"; 
string _subject = "Using the new SMTP client."; 
string _body = @"Using this new