今天一早 在asp.net(for c#)写了一个发送邮件的程序.可运行总报错 我正是没折了;cdo.message&cdo.newmail都有了 俺的代码如下:
private void Button1_Click(object sender, System.EventArgs e)
{
try
{
if(this.TextBox1.Text.Trim()=="")
{
this.LblMsg.Text = "目标邮箱不能为空。";
return;
}
MailMessage Message = new MailMessage();
Message.To = this.TextBox1.Text;
Message.From = "[email protected]";
Message.Subject = this.TextBox2.Text;
Message.Body = this.TextBox3.Text;
Message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "2"); //这个好像是认证类型
Message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "sswollow");//要认证的用户名
Message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "12345678");//要认证的密码 SmtpMail.Send(Message);
this.LblMsg.Text = "发送完毕!";
}
catch(Exception ex)
{
Page.Response.Write("The following exception occurred :"+ex.ToString());
while(ex.InnerException!=null)
{
Page.Response.Write("----------------------------------------------------");
Page.Response.Write("The following InnerException repeated :"+ex.InnerException.ToString());
ex = ex.InnerException;
}
}
}
有什么问题么??
private void Button1_Click(object sender, System.EventArgs e)
{
try
{
if(this.TextBox1.Text.Trim()=="")
{
this.LblMsg.Text = "目标邮箱不能为空。";
return;
}
MailMessage Message = new MailMessage();
Message.To = this.TextBox1.Text;
Message.From = "[email protected]";
Message.Subject = this.TextBox2.Text;
Message.Body = this.TextBox3.Text;
Message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "2"); //这个好像是认证类型
Message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "sswollow");//要认证的用户名
Message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "12345678");//要认证的密码 SmtpMail.Send(Message);
this.LblMsg.Text = "发送完毕!";
}
catch(Exception ex)
{
Page.Response.Write("The following exception occurred :"+ex.ToString());
while(ex.InnerException!=null)
{
Page.Response.Write("----------------------------------------------------");
Page.Response.Write("The following InnerException repeated :"+ex.InnerException.ToString());
ex = ex.InnerException;
}
}
}
有什么问题么??
试试
最好把错误信息帖一下
2。SmtpMail.SmtpServer = "smtp服务名";推荐:http://systemwebmail.com/
Message.To = "[email protected]";
Message.From = "[email protected]";
Message.Subject = "test";
Message.Body = "test";
Message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); Message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "sswollow");
Message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "12345678");
SmtpMail.Send(Message);运行报错 错误如下:
The following exception occurred :System.Web.HttpException: 未能访问“CDO.Message”对象。 ---> System.Reflection.TargetInvocationException: 调用的目标发生了异常。 ---> System.Runtime.InteropServices.COMException (0x80040211): The message could not be sent to the SMTP server. The transport error code was 0x800ccc15. The server response was not available --- 内部异常堆栈跟踪的结尾 --- at System.RuntimeType.InvokeDispMethod(String name, BindingFlags invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture, String[] namedParameters) at System.RuntimeType.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParameters) at System.Type.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args) at System.Web.Mail.LateBoundAccessHelper.CallMethod(Type type, Object obj, String methodName, Object[] args) at System.Web.Mail.LateBoundAccessHelper.CallMethod(Object obj, String methodName, Object[] args) --- 内部异常堆栈跟踪的结尾 --- at System.Web.Mail.LateBoundAccessHelper.CallMethod(Object obj, String methodName, Object[] args) at System.Web.Mail.CdoSysHelper.Send(MailMessage message) at System.Web.Mail.SmtpMail.Send(MailMessage message) at TreeViewDemo.SendMail.Button1_Click(Object sender, EventArgs e) in d:\asp.net应用程序\treeview\sendmail.aspx.cs:line 98----------------------------------------------------The following InnerException repeated :System.Reflection.TargetInvocationException: 调用的目标发生了异常。 ---> System.Runtime.InteropServices.COMException (0x80040211): The message could not be sent to the SMTP server. The transport error code was 0x800ccc15. The server response was not available --- 内部异常堆栈跟踪的结尾 --- at System.RuntimeType.InvokeDispMethod(String name, BindingFlags invokeAttr, Object target, Object[] args, Boolean[] byrefModifiers, Int32 culture, String[] namedParameters) at System.RuntimeType.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParameters) at System.Type.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args) at System.Web.Mail.LateBoundAccessHelper.CallMethod(Type type, Object obj, String methodName, Object[] args) at System.Web.Mail.LateBoundAccessHelper.CallMethod(Object obj, String methodName, Object[] args)----------------------------------------------------The following InnerException repeated :System.Runtime.InteropServices.COMException (0x80040211): The message could not be sent to the SMTP server. The transport error code was 0x800ccc15. The server response was not available