本文整理汇总了C#中Microsoft.Office.Interop.Outlook.Resolve方法的典型用法代码示例。如果您正苦于以下问题:C# Microsoft.Office.Interop.Outlook.Resolve方法的具体用法?C# Microsoft.Office.Interop.Outlook.Resolve怎么用?C# Microsoft.Office.Interop.Outlook.Resolve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Office.Interop.Outlook
的用法示例。
在下文中一共展示了Microsoft.Office.Interop.Outlook.Resolve方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetOutlookEmailAddress
public static string GetOutlookEmailAddress(string subject, Outlook.Recipient recipient)
{
string emailAddress = recipient.Address != null ? recipient.Address : recipient.Name;
switch (recipient.AddressEntry.AddressEntryUserType)
{
case Outlook.OlAddressEntryUserType.olExchangeUserAddressEntry: // Microsoft Exchange address: "/o=xxxx/ou=xxxx/cn=Recipients/cn=xxxx"
try
{
// The emailEntryID is garbage (bug in Outlook 2007 and before?) - so we cannot do GetAddressEntryFromID().
// Instead we create a temporary recipient and ask Exchange to resolve it, then get the SMTP address from it.
//Outlook.AddressEntry addressEntry = outlookNameSpace.GetAddressEntryFromID(emailEntryID);
//try
//{
recipient.Resolve();
if (recipient.Resolved)
{
Outlook.AddressEntry addressEntry = recipient.AddressEntry;
if (addressEntry != null)
{
try
{
if (addressEntry.AddressEntryUserType == Outlook.OlAddressEntryUserType.olExchangeUserAddressEntry)
{
Outlook.ExchangeUser exchangeUser = addressEntry.GetExchangeUser();
if (exchangeUser != null)
{
try
{
return exchangeUser.PrimarySmtpAddress;
}
finally
{
Marshal.ReleaseComObject(exchangeUser);
}
}
}
else
{
Logger.Log(string.Format("Unsupported AddressEntryUserType {0} for email '{1}' in appointment '{2}'.", addressEntry.AddressEntryUserType, addressEntry.Address, subject), EventType.Debug);
}
}
finally
{
Marshal.ReleaseComObject(addressEntry);
}
}
}
//}
//finally
//{
// if (recipient != null)
// Marshal.ReleaseComObject(recipient);
//}
}
catch (Exception ex)
{
// Fallback: If Exchange cannot give us the SMTP address, we give up and use the Exchange address format.
// TODO: Can we do better?
Logger.Log(string.Format("Error getting the email address of outlook appointment '{0}' from Exchange format '{1}': {2}", subject, emailAddress, ex.Message), EventType.Warning);
return emailAddress;
}
// Fallback: If Exchange cannot give us the SMTP address, we give up and use the Exchange address format.
// TODO: Can we do better?
return emailAddress;
case Outlook.OlAddressEntryUserType.olSmtpAddressEntry:
default:
return emailAddress;
}
}