当前位置: 首页>>代码示例>>C#>>正文


C# Microsoft.Office.Interop.Outlook.Resolve方法代码示例

本文整理汇总了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;
            }
        }
开发者ID:kcarnold,项目名称:googlesyncmod,代码行数:73,代码来源:AppointmentPropertiesUtils.cs


注:本文中的Microsoft.Office.Interop.Outlook.Resolve方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。