Reputation: 811
I am building a shared-addin for Outlook.
Inside the code, I am creating a reply email using MailItem.Reply()
method
and discarding it later. I am using this to get the sender email address
for emails coming through Exchange server.
It was working fine for Outlook 2007. But for Outlook 2010, the Reply method seems to opening the mail editor window.
I am on windows 7.
Is there any way to suppress that window or write seperate code based on Outlook version?
Upvotes: 2
Views: 726
Reputation: 31651
If you plan on discarding the message - don't create it to begin with (don't use Reply()
unless you intend on sending the message). You can use the Recipient
class to resolve an Exchange users email address with minimal resource utilization.
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;
}
Upvotes: 1