C# 如何获取文件夹项目关联的发件人电子邮件地址?(vsto/outlook 2010/mapi)
我的Outlook 2010加载项(c#)中有许多文件夹。它们在我的私人邮箱或共享邮箱中 现在,我正在寻找一个解决方案,以找出如何获得与专用文件夹相关联的正确电子邮件地址(发件人/收件人)。它可以是我私人邮箱中的任何文件夹,也可以是我共享邮箱中的任何文件夹 我想,也许我可以使用文件夹项中的EntryId/StoreId来标识相应的电子邮件地址C# 如何获取文件夹项目关联的发件人电子邮件地址?(vsto/outlook 2010/mapi),c#,vsto,outlook-addin,outlook-2010,mapi,C#,Vsto,Outlook Addin,Outlook 2010,Mapi,我的Outlook 2010加载项(c#)中有许多文件夹。它们在我的私人邮箱或共享邮箱中 现在,我正在寻找一个解决方案,以找出如何获得与专用文件夹相关联的正确电子邮件地址(发件人/收件人)。它可以是我私人邮箱中的任何文件夹,也可以是我共享邮箱中的任何文件夹 我想,也许我可以使用文件夹项中的EntryId/StoreId来标识相应的电子邮件地址 我已经知道,我可以从任何邮件项目中获得电子邮件地址,但我不想寻找这种解决方案。我想回答我自己的问题:我认为我找到了一个可行的解决方案 我不处理函数内部的任
我已经知道,我可以从任何邮件项目中获得电子邮件地址,但我不想寻找这种解决方案。我想回答我自己的问题:我认为我找到了一个可行的解决方案 我不处理函数内部的任何异常,我是从外部处理的
private string GetSMTPAddressByFolderItem(Outlook.MAPIFolder mapiFolder)
{
string PR_MAILBOX_OWNER_ENTRYID = @"http://schemas.microsoft.com/mapi/proptag/0x661B0102";
string PR_SMTP_ADDRESS = @"http://schemas.microsoft.com/mapi/proptag/0x39FE001E";
Outlook.Store store = null;
Outlook.NameSpace ns = null;
Outlook.AddressEntry sender = null;
Outlook._ExchangeUser exchUser = null;
try
{
if (mapiFolder == null)
{
return null;
}
// Get the parent store.
store = mapiFolder.Store;
string storeOwnerEntryId = store.PropertyAccessor.BinaryToString(store.PropertyAccessor.GetProperty(PR_MAILBOX_OWNER_ENTRYID)) as string;
ns = Application.GetNamespace(Constants.OL_NAMESPACE); // i.e. "MAPI"
sender = ns.GetAddressEntryFromID(storeOwnerEntryId);
if (sender != null)
{
if (sender.AddressEntryUserType == Outlook.OlAddressEntryUserType.olExchangeUserAddressEntry ||
sender.AddressEntryUserType == Outlook.OlAddressEntryUserType.olExchangeRemoteUserAddressEntry)
{
exchUser = sender.GetExchangeUser();
if (exchUser != null)
{
return exchUser.PrimarySmtpAddress;
}
else
{
return null;
}
}
else
{
return sender.PropertyAccessor.GetProperty(PR_SMTP_ADDRESS) as string;
}
}
return null;
}
finally
{
if (ns != null)
{
Marshal.ReleaseComObject(ns);
ns = null;
}
if (store != null)
{
Marshal.ReleaseComObject(store);
store = null;
}
if (sender != null)
{
Marshal.ReleaseComObject(sender);
sender = null;
}
if (exchUser != null)
{
Marshal.ReleaseComObject(exchUser);
exchUser = null;
}
}
}
你可以试着
skPrimaryExchangeMailbox = 3
skDelegateExchangeMailbox = 4
set Session = CreateObject("Redemption.RDOSession")
Session.MAPIOBJECT = Application.Session.MAPIOBJECT
for each Store in Session.Stores
If (Store.StoreKind = skPrimaryExchangeMailbox) or (Store.StoreKind = skDelegateExchangeMailbox) Then
MsgBox "Store " & Store.Name & " is owned by " & Store.Owner.Name
End If
next
您的意思是要查找父Exchange邮箱的所有者吗?是的,我的确切意思是.PR\u mailbox\u owner\u ENTRYID仅在联机模式下可用。缓存模式不会公开它。感谢您的提醒,我们不使用缓存模式。