请检查我的发邮件的代码为什么错误?
MailMessage mail = new MailMessage();
mail.To = "ming3232@21cn.com";
mail.From = "ming0987@163.com";
mail.Subject = "this is a test email.";
mail.Body = "Some text goes here";
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //basic authentication
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "ming0987"); //set your username here
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "123456"); //set your password here
SmtpMail.SmtpServer = "smtp.163.com"; //your real server goes here
SmtpMail.Send( mail );
================错误是:==================================================
异常详细信息: System.Runtime.InteropServices.COMException: The transport failed to connect to the server.
源错误:
行 62: SmtpMail.SmtpServer = "smtp.163.com"; //your real server goes here
行 63:
行 64: SmtpMail.Send( mail );
行 65: }
行 66: }
源文件: c:\inetpub\wwwroot\mailtest\webform1.aspx.cs 行: 64
堆栈跟踪:
[COMException (0x80040213): The transport failed to connect to the server.
]
[TargetInvocationException: 调用的目标发生了异常。]
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): 未能访问“CDO.Message”对象。]
System.Web.Mail.LateBoundAccessHelper.CallMethod(Object obj, String methodName, Object[] args) +112
System.Web.Mail.CdoSysHelper.Send(MailMessage message) +1846
System.Web.Mail.SmtpMail.Send(MailMessage message) +153
MailTest.WebForm1.Button1_Click(Object sender, EventArgs e) in c:\inetpub\wwwroot\mailtest\webform1.aspx.cs:64
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1277