Outlook 2007 vsto add-in. Get email sender address

前端 未结 4 1183
北荒
北荒 2020-12-31 11:38

I have a VSTO Outlook 2007 add-in. I am trying to get sender e-mail address when new email comes to Inbox.
To do it I use the following code:

void inbox         


        
4条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-31 12:04

    In Outlook 2007 you can do it like this:

    private string GetSmtpAddress(Outlook.MailItem oItem)
    {
        Outlook.Recipient recip;
        Outlook.ExchangeUser exUser;
        string sAddress;
    
        if (oItem.SenderEmailType.ToLower() == "ex")
        {
            recip = Globals.ThisAddIn.Application.GetNamespace("MAPI").CreateRecipient(oItem.SenderEmailAddress);
            exUser = recip.AddressEntry.GetExchangeUser();
            sAddress = exUser.PrimarySmtpAddress;
        }
        else
        {
            sAddress = oItem.SenderEmailAddress.Replace("'", "");
        }
        return sAddress;
    }
    

提交回复
热议问题