我正在开发Outlook 2007 VSTO加载项。我需要获取以下部分中指定的电子邮件地址:
info@xyz.com;代表; KANxyz SAXYZ [saxyz7@gmail.com]
我需要获取代码中的 [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){ }