高手救命!!!我编写的发送邮件程序,发送不成功,高手指点!代码见正文!!!

红三天 2004-12-28 03:24:26
老是发送不成功
private void btnSend_Click(object sender, System.EventArgs e)
{
//创建MailMessage对象
MailMessage MyMsg = new MailMessage();
MyMsg.From = tbFrom.Text;
MyMsg.To = tbTo.Text;
MyMsg.Subject = tbSubject.Text;
MyMsg.Priority = (MailPriority)ddlPriority.SelectedIndex;
MyMsg.BodyFormat= (MailFormat)ddlBodyFormat.SelectedIndex;
MyMsg.Body = tbBody.Text;

//如果有附件则上传
HttpPostedFile hpfFile = AttachFile.PostedFile;
if(hpfFile.FileName!="")
{
//有附件,则上传到Temp目录中
//取得文件名(不含路径)
char[] de = {'\\'};
string[] AFilename = hpfFile.FileName.Split(de);
string strFilename = AFilename[AFilename.Length-1];
string strPath = Server.MapPath(".")+"\\Temp\\"+strFilename;
hpfFile.SaveAs(strPath);
//添加附件
MyMsg.Attachments.Add(new MailAttachment(strPath));
}

try
{
//发送
SmtpMail.SmtpServer = "smtp.sina.com.cn";
SmtpMail.Send(MyMsg);
lblShowMsg.Text ="发送成功";
tbTo.Text = "";
tbSubject.Text = "";
tbBody.Text = "";
ddlPriority.SelectedIndex = 1;
ddlBodyFormat.SelectedIndex = 0;
}
catch(Exception ee)
{
lblShowMsg.Text = "发送失败:"+ee.ToString();
}
}
...全文
88 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
红三天 2004-12-28
  • 打赏
  • 举报
回复
都注册了啊~~~~~
whb147 2004-12-28
  • 打赏
  • 举报
回复
是不是没有注册组件呀?
红三天 2004-12-28
  • 打赏
  • 举报
回复
错误提示如下:

发送失败:System.Web.HttpException: 未能访问“CDO.Message”对象。 ---> System.Reflection.TargetInvocationException: 调用的目标发生了异常。 ---> System.Runtime.InteropServices.COMException (0x80040213): 与服务器的传输连接失败。 --- 内部异常堆栈跟踪的结尾 --- 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 WebApplicationMail.WebForm1.btnSend_Click(Object sender, EventArgs e) in c:\inetpub\wwwroot\webapplicationmail\webform1.aspx.cs:line 94

28,409

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧