110,571
社区成员
发帖
与我相关
我的任务
分享
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);
}