在Outlook 2007 VSTO代码中获取SentOnBehalfOfName的电子邮件地址

时间:2018-11-03 11:45:40

标签: vsto outlook-addin outlook-2007

我正在开发Outlook 2007 VSTO加载项。我需要获取以下部分中指定的电子邮件地址:

info@xyz.com;代表; KANxyz SAXYZ [saxyz7@gmail.com] enter image description here

我需要获取代码中的 [saxyz7@gmail.com] 。但是我只得到 SentOnBehalfOfName 属性,该属性仅返回名称(在本例中为“ KANxyz SAXYZ”)。

        try
        {

            Outlook.Selection objSelection = null;
            // Get the Application object
            Microsoft.Office.Interop.Outlook.Application application = Globals.ThisAddIn.Application;

            try
            {
                var window = application.ActiveWindow();
                try
                {
                    objSelection = application.ActiveExplorer().Selection;
                }
                catch (System.Exception ex)
                {
                    //Ignore; NULL check below will branch out 
                }
                objMail = default(Outlook.MailItem);

                try
                {
                    objMail = objSelection[1];
                }
                catch (Exception ex)
                {
                }
                if ((objMail != null) && !string.IsNullOrEmpty(objMail.SenderEmailAddress))
                {
                    email = objMail.SenderEmailAddress;
                    emailFrom = objMail.SentOnBehalfOfName;
                }
            }
            catch { }

            if ((objMail == null) || string.IsNullOrEmpty(objMail.SenderEmailAddress))
            {
                // Get the active Inspector object and check if is type of MailItem
                Microsoft.Office.Interop.Outlook.Inspector inspector = application.ActiveInspector();
                if (inspector != null)
                {
                    mailItem = inspector.CurrentItem as Microsoft.Office.Interop.Outlook.MailItem;
                    if (mailItem != null)
                    {
                        email = mailItem.SenderEmailAddress;
                        emailFrom = objMail.SentOnBehalfOfName;
                    }       
                }
            }
        }
        catch (Exception ex){ }

0 个答案:

没有答案