public static void SendMail(string from,string to, string subject,string body) 

if (ConfigurationSettings.AppSettings["SendMail"] == "true") //这里是获取系统设置

MailMessage mm = new MailMessage();  mm.From = from;
mm.To = to; mm.Subject = subject;
mm.Body = body; mm.BodyFormat = MailFormat.Text;
                
                  //设置为需要用户验证 
                  mm.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");                     //设置验证用户名(把my_username_here改为你的验证用户名) 
                  mm.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "/cdo/configuration/sendpassword", "我的密码");                  SmtpMail.SmtpServer = "mail.yahoo.com";  //邮件服务器地址           SmtpMail.Send(mm);
}
}出错的TraceStack Trace:
[COMException (0x80040213): The transport failed to connect to the 
server.
][TargetInvocationException: Exception has been thrown by the target of 
an invocation.]
System.RuntimeType.InvokeDispMethod(String name, BindingFlags 
invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers, Int32 
culture, String[] namedParameters) +0
System.RuntimeType.InvokeMember(String name, BindingFlags invokeAttr, 
Binder binder, Object target, Object[] args, ParameterModifier[] 
modifiers, CultureInfo culture, String[] namedParameters) +473
System.Web.Mail.LateBoundAccessHelper.CallMethod(Object obj, String 
methodName, Object[] args) +58[HttpException (0x80004005): Could not access 'CDO.Message' object.]
System.Web.Mail.LateBoundAccessHelper.CallMethod(Object obj, String 
methodName, Object[] args) +111
System.Web.Mail.CdoSysHelper.Send(MailMessage message) +1861
System.Web.Mail.SmtpMail.Send(MailMessage message) +150
ReflexAccessories.compoment.MailTo.SendMail(String from, String to, 
String subject, String body) +218
ReflexAccessories.reg.ibnSubmit_Click(Object sender, 
ImageClickEventArgs e) +460
System.Web.UI.WebControls.ImageButton.OnClick(ImageClickEventArgs e) 
+109
System.Web.UI.WebControls.ImageButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String 
eventArgument) +69
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler 
sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1292我是根据论坛里之前的帖子教的方法写的,还是错,请高手帮帮忙,看看是什么问题~谢谢!

解决方案 »

  1.   

    你可以使用Jmail组件!
    http://blog.csdn.net/kenMoxi/archive/2004/08/18/77810.aspx
      

  2.   

    http://www.cnblogs.com/goody9807/archive/2005/03/09/115367.html看看是不是防火墙的原因!
      

  3.   

    yahoo,好像不支持smtp的吧?你是交钱的那种?
    尝试一下其它的smtp服务器?
      

  4.   

    yahoo,好像不支持smtp的吧?你是交钱的那种?
    尝试一下其它的smtp服务器?有这种事?那我换一个163的试试。