我编写了个发送邮件的程序:发送时出现如下错误:
发送失败:System.Web.HttpException: 未能访问“CDO.Message”对象
请问是怎么回事.

解决方案 »

  1.   

    /创建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;
    MyMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");  MyMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername","[email protected]");  MyMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "53344521binbin");

    //如果有附件则上传
    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.Send(MyMsg);
    lblShowMsg.Text ="发送成功";
    tbTo.Text = "";
    tbSubject.Text = "";
    tbBody.Text = "";
    ddlPriority.SelectedIndex = 1;
    ddlBodyFormat.SelectedIndex = 0;
    }
    catch(Exception ee)
    {
    lblShowMsg.Text = "发送失败:"+ee.ToString();
    }
    }