首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

高分求救——SMTP发送邮件的有关问题

2012-01-22 
高分求救——SMTP发送邮件的问题我写了一段用SMTP发送邮件的代码,但是发送之后收不到邮件,代码如下:MailMess

高分求救——SMTP发送邮件的问题
我写了一段用SMTP发送邮件的代码,但是发送之后收不到邮件,代码如下:
  MailMessage message = new MailMessage();
  message.From = new MailAddress("ddewafa@126.com");
  message.To.Add("etttew@live.cn");
  message.Subject = "This is test";
  message.Body = "Test!";
  message.IsBodyHtml = true;
  SmtpClient mail = new SmtpClient();
  mail.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis;
  mail.Host = "smtp.126.com";
  mail.Port = 25;
  mail.Credentials = new NetworkCredential("ddewafa@126", "dfweee");
  try
  {
  mail.Send(message);
  }
  catch(Exception ex)
  {
  throw new Exception(ex.ToString());
  }
请问问题出在了哪儿,我用mail.DeliveryMethod = SmtpDeliveryMethod.Network;也不行,是不是还要配置什么啊,IIS需要配置吗?怎么办啊

[解决办法]
没有异常信息吗
[解决办法]
不需要配置.试试其他方法
参考
http://www.cnblogs.com/Hedonister/articles/167483.html
http://www.cnblogs.com/xpengfee/articles/623874.html
[解决办法]
某些SMTP服务器会因为你带宽窄发生超时,邮件就发不出去了
[解决办法]
代理上网应该没问题的。
收发的邮件服务器换个其他的试试。
[解决办法]
今天是不是收到了??
[解决办法]
是不是因为163邮箱需要ssl认证,我用outlook express好像也发不出去
[解决办法]
using System.Web.Mail;
public void sendMail()
{
 try
 {
System.Web.Mail.MailMessage myMail=new MailMessage();
myMail.From = "myaccount@test.com";
myMail.To = "myaccount@test.com";
myMail.Subject = "MailTest";
myMail.Priority = MailPriority.Low;
myMail.BodyFormat = MailFormat.Text;
myMail.Body = "Test";
SmtpMail.SmtpServer="smarthost"; //your smtp server here
 
SmtpMail.Send(myMail);
 }
 catch(Exception e)
 {
throw e;
 }
}
如果这样也不行
使用CDO组件发送邮件
  CDO是Collaboration Data Objects的简称,它是一组高层的COM对象集合,并经历了好几个版本的演化,现在在Windows2000和Exchange2000中使用的都是CDO2.0的版本(分别为cdosys.dll和cdoex.dll)。CDOSYS构建在SMTP协议和NNTP协议之上,并且作为Windows2000 Server的组件被安装,您可以在系统目录(如c:\winnt或c:\windows)的system32子目录中找到它(cdosys.dll)。
  CDO组件相对于先前介绍的SmtpMail对象功能更为丰富,并提供了一些SmtpMail类所没有提供的功能,如通过需要认证的SMTP服务器发送邮件等。
下面一段代码就展示了如何使用CDO组件通过需要认证的SMTP服务器发送邮件的过程:
(in C#)
public void CDOsendMail()
{
 try
 {
CDO.Message oMsg = new CDO.Message();

oMsg.From = "myaccount@test.com";
oMsg.To = "myaccount@test.com";
oMsg.Subject = "MailTest";

oMsg.HTMLBody = "<html><body>Test</body></html>";
 
CDO.IConfiguration iConfg = oMsg.Configuration;
ADODB.Fields oFields = iConfg.Fields;

oFields["http://schemas.microsoft.com/cdo/configuration/sendusing"].Value=2;
oFields["http://schemas.microsoft.com/cdo/configuration/sendemailaddress"].Value="myaccount@test.com"; //sender mail


oFields["http://schemas.microsoft.com/cdo/configuration/smtpaccountname"].Value="myaccount@test.com"; //email account
oFields["http://schemas.microsoft.com/cdo/configuration/sendusername"].Value="username";
oFields["http://schemas.microsoft.com/cdo/configuration/sendpassword"].Value="password";
oFields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"].Value=1;
//value=0 代表Anonymous验证方式(不需要验证)
//value=1 代表Basic验证方式(使用basic (clear-text) authentication.
//The configuration sendusername/sendpassword or postusername/postpassword fields are used to specify credentials.)
//Value=2 代表NTLM验证方式(Secure Password Authentication in Microsoft Outlook Express)
oFields["http://schemas.microsoft.com/cdo/configuration/languagecode"].Value=0x0804;
oFields["http://schemas.microsoft.com/cdo/configuration/smtpserver"].Value="smtp.21cn.com";
 
oFields.Update();
oMsg.BodyPart.Charset="gb2312";
oMsg.HTMLBodyPart.Charset="gb2312";
 
oMsg.Send();
oMsg = null;
 }
 catch (Exception e)
 {
throw e;
 }
}
注意:由于Exchange2000的CDO组件cdoex.dll会更新原有的Windows2000的CDO组件cdosys.dll,所以如果您希望继续使用cdosys.dll,您必须先通过regsrv32.exe卸载掉cdoex.dll。

看看这个,用别的方法试一试可能可以
[解决办法]
建议到官网查查ddewafa@126.com邮箱是否支持SMTP和POP3
网易的免费邮箱好象06年以后注册的都不支持了
[解决办法]
MailMessage message = new MailMessage(); 
message.From = new MailAddress("ddewafa@126.com"); 
message.To.Add("etttew@live.cn"); 
message.Subject = "This is test"; 
message.Body = "Test!"; 
message.IsBodyHtml = true; 
SmtpClient mail = new SmtpClient(); 
mail.DeliveryMethod = SmtpDeliveryMethod.PickupDirectoryFromIis; 
mail.Host = "smtp.126.com"; 
mail.Port = 25; 
mail.Credentials = new NetworkCredential("ddewafa@126", "dfweee"); 
try 

mail.Send(message); 

catch(Exception ex) 

throw new Exception(ex.ToString()); 

==================================================
应该是mail.Host = "smtp.126.com"; 这个邮件网关的问题,这种proxy不会接受这种授权

[解决办法]
不一定是你的代码有问题

热点排行