Hi,
I would like to retrieve the alias email that would have been emailed on the Shared Mailbox but Exchange overrides the "To recipient" with the Primary email address of the shared mailbox
Example - Alias is emailed in the following shared mailbox. I would like to retrieve the "aa@alias.co.uk" email
PrimaryEmail - aa@primarydomain.co.uk
Alias Email - aa@alias.co.uk
I have tried accessing the header but, no luck
Following is my 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<Item> 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);
}
}
}
}
Every day i learn something new.