2016-02-29 70 views
0

我需要知道会议请求相关联(电子邮件地址的会议请求被发送到)帐户的电子邮件地址:如何获取与会议请求关联的帐户?

string GetAssociatedAccountEmailAddress(Outlook.MeetingItem meetingItem) 
{ 
    //TODO: implement this method: 
    throw new NotImplementedException(); 
} 

这是我的尝试:

string GetAssociatedAccountEmailAddress1(Outlook.MeetingItem meetingItem) 
{ 
    Outlook.MAPIFolder folder = meetingItem.Parent; 
    Debug.WriteLine("Folder Name: {0}, Folder Path: {1}", folder.Name, folder.FolderPath); 

    Outlook.MAPIFolder folderParent = folder.Parent; 
    Debug.WriteLine("Folder Parent Name: {0}, Folder Parent Path: {1}", folderParent.Name, folderParent.FolderPath); 

    return folderParent.FolderPath.Replace("\\", ""); 
} 

调试输出:

Folder Name: Inbox, Folder Path: \\\\[email protected]\Inbox 
Folder Parent Name: [email protected], Folder Parent Path: \\\\[email protected] 

此实现的问题是,我不确定文件夹路径将始终包含电子邮件地址。

我也试过如下:

string GetAssociatedAccountEmailAddress2(Outlook.MeetingItem meetingItem) 
{ 
    Outlook.MAPIFolder folder = meetingItem.Parent; 

    Outlook.MAPIFolder folderParent = folder.Parent; 

    Outlook.NameSpace ns = folderParent.Parent; 
    return ns.Accounts.Cast<Outlook.Account>() 
     .FirstOrDefault(x => meetingItem.Recipients.Cast<Outlook.Recipient>().Any(r => r.Address == x.SmtpAddress)) 
     .SmtpAddress; 
} 

这样做的问题是,如果我有两个账户([email protected][email protected])和会议请求被发送到两个,那么我有两个会议请求,但GetAssociatedAccountEmailAddress2返回相同的电子邮件地址。

FYI:我开发一个Outlook中使用VS 2015

+0

那么,两个会议请求都有相同的收件人,所以难怪你会得到相同的结果 - 你的代码返回第一个匹配的地址。你需要看看父母的商店并找出它的主人。 –

+0

@DmitryStreblechenko。什么的父母?我查看GetAssociatedAccountEmailAddress1上的父级,但它似乎不是正确的方法?你能详细说明一下吗?请。 –

+0

我是指会议请求所在文件夹的父商店。 –

回答

1

几种方法可以做到这一点添加用于Outlook 2013 -

  1. 阅读PR_RECEIVED_BY_ENTRYID财产(不保证目前, DASL名称http://schemas.microsoft.com/mapi/proptag/0x003F0102)使用MeetingItem.PropertyAccessor.GetProperty,使用PropertyAccessor.BinaryToString将其转换为十六进制字符串,用它来呼叫Application.Session.GetAddressEntryFromID。请注意,如果商品是从其他商店复制的,则该商品可能与实际商店所有者不匹配。通过OutlookSpy(单击IMessage按钮)查看会议请求以查看该属性。

  2. 阅读使用Store.PropertyAccessor.GetProperty父存储(MeetingItem.Parent.Store)的PR_MAILBOX_OWNER_ENTRYID属性(DASL名http://schemas.microsoft.com/mapi/proptag/0x661B0102)。该物业不保证存在。如果使用Redemption是一个选项,它将公开具有所有者属性的RDOExchangeMailboxStore对象(返回RDOAddressEntry obejcy)。

+0

谢谢。第一个为我工作。我认为我需要尝试两种方式,如果两者都不起作用,就会后备。 –

相关问题