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。
就进行不下去了!不知道怎么办啊!
求大大们帮忙!
...全文
130 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用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;
}
内容概要:本文详细探讨了机组组合优化模型的构建,旨在通过合理安排各类发电机组的启停计划和优化出力分配,实现电力系统在经济性和稳定性上的最佳平衡。文章首先介绍了电力系统的四大主要组件——传统火电机组、风电机组、光伏机组和储能系统的参数及运行特性。接着,围绕最小化系统总运行成本这一目标,设计了优化目标函数,并明确了包括功率平衡约束、机组出力上下限约束、风光发电功率约束、弃风弃光约束、爬坡速率约束、储能系统荷电状态约束、充放电功率约束和充放电互斥约束在内的多项约束条件。最后,文章列出了求解机组组合优化模型所需的关键变量,如传统机组的开停状态、机组出力、启停成本、风电光伏实际出力、弃风弃光比例及储能系统的充放电功率和荷电状态,以实现系统的经济调度和可再生能源的最大化利用。 适合人群:从事电力系统研究、规划和调度工作的工程师和技术人员,以及对电力系统优化感兴趣的科研人员。 使用场景及目标:①帮助电力系统工程师理解不同类型发电机组的特点及其对系统稳定性、经济性和环保性的影响;②为制定合理的电力系统调度策略提供理论依据和技术支持;③促进可再生能源的有效整合,提高电力系统的灵活性和可靠性。 其他说明:本文提供的模型和方法不仅适用于当前的电力系统,也可为未来含高比例可再生能源接入的电力系统提供参考。文涉及的具体数学公式和参数设定为实际应用提供了详细的指导,有助于提升电力系统的运行效率和经济效益。

111,094

社区成员

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

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

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