使用Jacob库删除和更新Outlook联系人 [英] Delete and update Outlook contact using jacob library
问题描述
我正在使用jacob库.使用jacob库并遵循本教程能够在Outlook中添加联系人.现在,我想使用雅各布删除和更新该联系人.我想知道是否可以使用jacob删除Outlook联系人.
I am using jacob library. Using jacob library and following this tutorial i am able to add a contact in outlook. Now i want to delete and update that contact using jacob. i want to know is there any way to delete the outlook contact using jacob.
我正在使用此代码在Outlook中添加联系人.此处的电子邮件ID是唯一ID.
I am using this code to add contact in outlook. here email id is unique id.
ActiveXComponent axOutlook = new ActiveXComponent("Outlook.Application");
Dispatch oOutlook = axOutlook.getObject();
Dispatch createContact = Dispatch.call((Dispatch)oOutlook, "CreateItem", new Variant(2)).toDispatch();
Dispatch.put(createContact,"LastName",cont.getLastName());
Dispatch.put(createContact,"FirstName",cont.getFirstName());
Dispatch.put(createContact,"Title",cont.getTitle());
Dispatch.put(createContact,"Email1Address",cont.getPrimaryEmail());
Dispatch.call(createContact, "Save");
推荐答案
JACOB是围绕COM IDispatch调用的非常薄的包装器,因此,如果您想知道如何在Outlook中执行任何特定任务,起点将是正式的 Outlook对象模型文档
JACOB is a very thin wrapper around COM IDispatch calls, so if you want to know how to do any particular task in Outlook the starting point would be the official Outlook Object Model documentation
您的特殊情况是通过
namespace = outlookApplication.GetNamespace("MAPI")
contactsFolder = namespace.GetDefaultFolder(olFolderContacts)
contact = contactsFolder.items.find( "[Email1Address] = 'mail@server.com' )
if (contact != null)
{
contact.Delete
}
第二部分工作是将这些调用转换为JACOB语音.假设您已找到联系人项目,则代码应类似于
The second half of the work is translating these calls to JACOB-speak. Assuming you have located your contact item, the code would be something like
ActiveXComponent outlookApplication = new ActiveXComponent("Outlook.Application");
Dispatch namespace = outlookApplication.getProperty("Session").toDispatch();
Dispatch contactsFolder = Dispatch.call(namespace, "GetDefaultFolder", new Integer(10)).toDispatch();
Dispatch contactItems = Dispatch.get(contactsFolder, "items");
String filter = String.format("[Email1Address] = '%s'", cont.getPrimaryEmail());
Dispatch contact = Dispatch.call(contactItems, "find", filter);
if (contact != null)
{
Dispatch.call(contactItem, "Delete");
}
这篇关于使用Jacob库删除和更新Outlook联系人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!