Outlook 2007 vsto add-in. Get email sender address

前端 未结 4 1168
北荒
北荒 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 11:58

    You can use inspector to get current email as follow.

     Outlook.Inspector inspector = Globals.ThisAddIn.Application.ActiveInspector();
                if (inspector != null)
                {
                    Outlook.MailItem  mi = inspector.CurrentItem as Outlook.MailItem;
    
                  //Then identify whether email sender is exchange user or normal user
                   string senderEmail=null;
                   if (mi.SenderEmailType == "EX")
                    {
                    senderEmail = mi.Sender.GetExchangeUser().PrimarySmtpAddress;                    
                     }
                  else
                    {
                     senderEmail=mi.SenderEmailAddress;
                    }
                 }
    

    you will get sender email in senderEmail variable.

提交回复
热议问题