【问题标题】:Trying To Connect Outlook Using C#尝试使用 C# 连接 Outlook
【发布时间】:2014-10-31 05:46:29
【问题描述】:

我正在尝试使用 c# 获取 Outlook 功能(附件、邮件、联系人)。

示例代码:

using System.Text;
using Microsoft.Office.Interop.Outlook;

namespace Happy_bday_automation
{
    class Program
    {
        private void SendEmailtoContact(string name)
        {
            string subjectEmail = "Happy Bday" + name;
            string bodyEmail = "Meeting is one hour later.";
            ContactItem contact1 = new ContactItem();
            contact1.Email1Address=name+"@ca.com";
            this.CreateEmailItem(subjectEmail, contact1.Email1Address, bodyEmail);
        }
}
}

所以当我创建 contactItem 对象时,我会收到类似的错误

在 mscorlib.dll 中发生“System.Runtime.InteropServices.COMException”类型的未处理异常

附加信息:检索 CLSID 为 {00061031-0000-0000-C000-000000000046} 的组件的 COM 类工厂失败,原因是以下错误:80040154 未注册类(HRESULT 异常:0x80040154 (REGDB_E_CLASSNOTREG))。

请提出一些解决方案:)

提前致谢。

【问题讨论】:

标签: c# outlook registry office-interop


【解决方案1】:

ContactItem 不是可创建对象,只有 Outlook.Application 是。

可以使用Application.CreateItem(OlItemType.olContactItem)MAPIFolder.Items.Add("IPM.Contact") 创建新联系人,其中 MAPIFolder 是一个联系人文件夹。可以使用Application.Session.GetDefautlFolder(olFolderContacts) 检索默认联系人文件夹。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-07-18
    • 1970-01-01
    • 1970-01-01
    • 2017-08-17
    • 1970-01-01
    • 2014-09-18
    • 1970-01-01
    相关资源
    最近更新 更多