title: Retrieve Alias From SharedMailbox
body: <p>I would like to retrieve the alias email that would have been emailed to a Shared Mailbox but Exchange overrides the "To recipient" with the Primary email address of the shared mailbox</p>
  
  <p>Example - "aa@alias.co.uk" Alias is emailed on the shared mailbox. I would like to retrieve the "aa@alias.co.uk" email</p>
  
  <p>PrimaryEmail -   aa@primarydomain.co.uk</p>
  
  <p>Alias Email       - aa@alias.co.uk</p>
  
  <p>I have tried accessing the headers of the email but, no luck</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using Microsoft.Exchange.WebServices.Data;
  
  namespace readSharedMailbox
  {
      class Program
      {
          static void Main(string[] args)
          {
              ExchangeService _service;
              try
              {
                  Console.WriteLine("Registering Exchange connection");
                  _service = new ExchangeService
                  {
                      Credentials = new WebCredentials("*******", "********")
                  };
              }
              catch
              {
                  Console.WriteLine("new ExchangeService failed. Press enter to exit:");
                  return;
              }
              // Office365 webservice URL
              _service.Url = new Uri("https://outlook.office365.com/EWS/Exchange.asmx");
              try
              {
                  Console.WriteLine("Reading mail");
                  FindItemsResults&lt;Item&gt; result = _service.FindItems(WellKnownFolderName.Inbox, new ItemView(1));
  
                  foreach (Item item in result)
                  {
                      EmailMessage message = EmailMessage.Bind(_service, item.Id);
                      Console.WriteLine("Reading items");
                      Console.WriteLine(message.ToRecipients[0].Address.ToString());
                      /* Reading the Header
  
                      foreach (var property in message.InternetMessageHeaders)
                      {
                          Console.WriteLine(property.Name);
                          Console.WriteLine(property.Value);
                      }
                      */
                  }
                  Console.WriteLine("Exiting");
                  Console.ReadLine();
              }
              catch (Exception e)
              {
                  Console.WriteLine("An error has occured. \n:" + e.Message);
              }
          }
      }
  </code></pre>
  
  <p>}</p>