Get Mail Address of Sender from Outlook Mail Item Object by C#

Here is a C# code example that will help you to find the mail ID of sender from Outlook Mail Item Object. We use SenderEmailType property of Outlook MailItem object to determine the email type of sender. Then based on sender email type we retrieve the sender mail ID.

Below C# code snippet iterates to each mail in Inbox. It checks email type of sender whether it is SMTP or EX and then gets sender mail ID by using SenderEmailAddress or Sender.GetExchangeUser().PrimarySmtpAddress properties.

foreach (Outlook.MailItem oMsg in oInbox.Items)
{
  if (oMsg.SenderEmailType == "SMTP")
    {
      Console.WriteLine(oMsg.SenderEmailAddress);
    }
  else if (oMsg.SenderEmailType == "EX")
    {
      Console.WriteLine(oMsg.Sender.GetExchangeUser().PrimarySmtpAddress);
    }
}

You can refer to this post for more info about oMsg, Outlook MailItem object.

Leave a Reply