在 Outlook 中取消删除联系人
我有一个用 Delphi 编写的应用程序,可以在 Outlook 中添加/更新联系人。我遇到的问题是,如果联系人已在 Outlook 中删除,代码仍会找到该联系人并进行更新 - 并且该联系人仍保持删除状态。有没有办法确定联系人是否已删除或取消删除联系人?
代码大致如下:
OutlookApp := CreateOleObject('Outlook.Application');
Mapi := OutlookApp.GetNameSpace('MAPI');
//.....
try
if ContactOutlookEntryID.AsString <> '' then
aContact := Mapi.GetItemFromID(ContactOutlookEntryID.AsString);
except
end;
//try to locate the contact if they have been synchro'd before
if VarIsEmpty(aContact) then //if not found
aContact := Contacts.Items.Add(2); //add a new contact to outlook
aContact.LastName := ContactSurname.AsString;
//.....
I have an application written in Delphi that adds / updates contacts in outlook. The problem I'm having is that if the contact has been deleted in Outlook, the code still finds the contact and updates it - and the contact still remains deleted. Is there a way I can determine if the contact is deleted or undelete the contact?
Roughly the code looks something like:
OutlookApp := CreateOleObject('Outlook.Application');
Mapi := OutlookApp.GetNameSpace('MAPI');
//.....
try
if ContactOutlookEntryID.AsString <> '' then
aContact := Mapi.GetItemFromID(ContactOutlookEntryID.AsString);
except
end;
//try to locate the contact if they have been synchro'd before
if VarIsEmpty(aContact) then //if not found
aContact := Contacts.Items.Add(2); //add a new contact to outlook
aContact.LastName := ContactSurname.AsString;
//.....
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
删除联系人后,它们会被放入“已删除邮件”文件夹中。除了位于该文件夹中之外,没有其他“已删除”状态。 “取消删除”就像将其移回一样简单。
ContactItem 对象上有一个 Move 方法,您可以使用它来将其移回默认联系人文件夹,您可以通过 NameSpace.GetDefaultFolder 方法。
编辑
要确定联系人是否位于已删除项目文件夹中,您可以查看 Parent 属性,该属性应返回 MAPIFolder 对象。然后,您可以将其 EntryID 与 GetDefaultFolder(olFolderDeletedItems) 返回的 EntryID 进行比较。
When contacts are deleted they are put in the Deleted Items folder. There is no other "deleted" state other than being in that folder. "Undeleting" is as simple as moving it back out.
There is a Move method on the ContactItem object that you can use to move it back to the default contact folder which you can get with the NameSpace.GetDefaultFolder method.
EDIT
To determine if the contact is in the deleted items folder you can look at the Parent property which should return a MAPIFolder object. You can then compare its EntryID against the one returned by GetDefaultFolder(olFolderDeletedItems).
请记住,这是特定于 PST 的 - 当项目移动到不同的文件夹时,PST 提供程序不会更改条目 ID。
德米特里·斯特雷布莱琴科 (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook,CDO
和 MAPI 开发工具
Keep in mind that this is PST specific - the PST provider does not change the entry id when items are moved to different folders.
Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool