win7+VS2008编译的CDO发送EMAIL程序在XP环境中使用出错

seaer06 2011-10-29 06:53:27
我使用win7+VS2008为环境做了一个发送EMAIL的程序,使用的是CDO.Message,在WIN7下测试无任何错误,可是在XP下使用,出现下面的错误:

Unable to cast COM object of type 'System.__ComObject' to interface type 'ADODB.Fields'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{00001564-0000-0010-8000-00AA006D2EA4}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).

以下是我的代码:

//实例化MAIL
CDO.Message oMsg = new CDO.Message();


//添加收件人
oMsg.To = ToTb.Text;

//添加CC
oMsg.CC = CCTb.Text;
//添加Subject
oMsg.Subject = SubjectTb.Text;
if (!string.IsNullOrEmpty(((EditTask)Application.OpenForms["EditTask"]).AttachedFdg.FileName))
{
oMsg.AddAttachment(((EditTask)Application.OpenForms["EditTask"]).AttachedFdg.FileName, "", "");
}
oMsg.From = emailfrom;
oMsg.HTMLBody = MailContentBrower.DocumentText;

oMsg.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/sendusing"].Value = sendusing;
oMsg.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/sendemailaddress"].Value =emailfrom; //sender mail
oMsg.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpaccountname"].Value = emailfrom; //email account
oMsg.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/sendusername"].Value =username;
oMsg.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/sendpassword"].Value = pwd;
oMsg.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"].Value =authenticate;
//value=0 代表Anonymous验证方式(不需要验证)
//value=1 代表Basic验证方式(使用basic (clear-text) authentication.
//The configuration sendusername/sendpassword or postusername/postpassword fields are used to specify credentials.)
//Value=2 代表NTLM验证方式(Secure Password Authentication in Microsoft Outlook Express)
//oMsg.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/languagecode"].Value = 0x0804;
oMsg.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserver"].Value = servername;
oMsg.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserverport"].Value = serverport;
oMsg.Configuration.Fields["http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout"].Value =connectiontimeout;



oMsg.Configuration.Fields.Update();
oMsg.BodyPart.Charset = "gb2312";
oMsg.HTMLBodyPart.Charset = "gb2312";



oMsg.Send();
oMsg = null;
SendingImg.Visible = false;
MessageBox.Show("Email发送成功!", "发送成功", MessageBoxButtons.OK, MessageBoxIcon.Information);

}
catch (Exception ex)
{
if (conn.State != ConnectionState.Closed)
{
conn.Close();
}
SendingImg.Visible = false;
MessageBox.Show("发送Email时发生错误:" + ex.Message, "发生错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}

苦恼啊,找了一个星期没找出问题所在。
但是看到Microsoft的以下解释:
http://support.microsoft.com/kb/2517589/en-us
可是按照他的说明去在WIN7上做,进行到第三步时,会出现错误:RegisterTypeLib of "C:\program file\commonfiles\system\ado\msado60_Backcompat.tlb" failed:8002801C。
就进行不下去了!不知道怎么办啊!
求大大们帮忙!
...全文
117 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
seaer06 2011-11-03
  • 打赏
  • 举报
回复
哎,无功而返。
系统一不小心被我GHOST成XP了。
这下省事了。
seaer06 2011-10-29
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 a21999 的回复:]

不需要什么CDO,你可以看看.NET内置的发送方式,比你这个稳定的多。

public bool Send()
{
MailMessage Msg = new MailMessage();
Msg.BodyEncoding = System.Text.Encoding.UTF8;
Msg.I……
[/Quote]
MailMessage我也使用过,但是在公司的内部网络也出错,所以又改用CDO:
出错情况我在另外一个贴子也求助过!
http://topic.csdn.net/u/20111027/12/bf0c01f1-0519-4811-9da9-d9ffefdc4ac9.html
a21999 2011-10-29
  • 打赏
  • 举报
回复
不需要什么CDO,你可以看看.NET内置的发送方式,比你这个稳定的多。

public bool Send()
{
MailMessage Msg = new MailMessage();
Msg.BodyEncoding = System.Text.Encoding.UTF8;
Msg.IsBodyHtml = true;

Msg.From = new MailAddress(myEmail, myNickName);
Msg.To.Add(new MailAddress(mailPerson));
Msg.Subject = mailTitle;
Msg.Body = mailBody;
Msg.BodyEncoding = System.Text.Encoding.UTF8;
Msg.Priority = MailPriority.High;
SmtpClient clint = new SmtpClient(mailSmtpServer);
clint.UseDefaultCredentials = false;

clint.Credentials = new System.Net.NetworkCredential(myId, myPwd);
clint.DeliveryMethod = SmtpDeliveryMethod.Network;
clint.EnableSsl = false;


//添加附件
if (paths.Count != 0)
{
foreach (string path in paths)
{
Attachment data = new Attachment(path, System.Net.Mime.MediaTypeNames.Application.Octet);
Msg.Attachments.Add(data);
}
}
try
{

clint.Send(Msg);


}
catch (........)
{
...
}
finally
{............

}
return true;
}

110,571

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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