我正在为Outlook构建共享插件。

在代码内部,我正在使用MailItem.Reply()方法创建回复电子邮件
然后将其丢弃。我正在使用它来获取发件人的电子邮件地址
用于通过Exchange服务器发送的电子邮件。

对于Outlook 2007,它运行良好。
但是对于Outlook 2010,Reply方法似乎打开了邮件编辑器窗口。

我在Windows 7上。

有什么方法可以抑制该窗口或根据Outlook版本编写单独的代码?

最佳答案

如果您打算丢弃该消息,请不要创建它开头(除非打算发送该消息,否则请不要使用Reply())。您可以使用Recipient类来以最少的资源使用来解析Exchange用户的电子邮件地址。

string senderEmail = string.Empty;
Outlook.Recipient recipient = mailItem.Application.Session.CreateRecipient(mailItem.SenderEmailAddress);
if (recipient != null && recipient.Resolve() && recipient.AddressEntry != null)
{
    Outlook.ExchangeUser exUser = recipient.AddressEntry.GetExchangeUser();
    if (exUser != null && !string.IsNullOrEmpty(exUser.PrimarySmtpAddress))
       senderEmail = exUser.PrimarySmtpAddress;
}

10-07 12:08