Mark
Mark

Reputation: 13

Accessing email properties in Exchange web server managed API

I'm a complete newbie to EWS, but am trying to convert a happily functioning IMAP program into EWS & am having problems accessing simple fields in the managed API, e.g. From, Sender, BodyType. Can anyone spot what I am doing wrong? Many thanks folks.

        ItemView view = new ItemView(99);
        SearchFilter.Exists filter = new SearchFilter.Exists(EmailMessageSchema.Id);
        FindItemsResults<Item> inboxMessageList = service.FindItems(WellKnownFolderName.Inbox, view);
        Console.WriteLine("Inbox message count: " + inboxMessageList.TotalCount);
        int messageCounter = 1;

        //message loop
        foreach (Item thisMessage in inboxMessageList)
        {
            //Collect info about current email message
            Item thisItem = Item.Bind(service, thisMessage.Id);
            Console.WriteLine("Current message ID: " + thisMessage.Id);

            string uniqueID = "EMAIL-" + DateTime.UtcNow.ToString("yyyyMMdd-HHmmss-fff");
            string messageTo = thisItem.DisplayTo;
            string messageCC = thisItem.DisplayCc;
            string messageFrom = //cant get this to work
            string messageSubject = thisItem.Subject;
            string messageDate = thisMessage.DateTimeReceived.ToString();
            int noOfAttachments = 0;
            Boolean messageHasAttachments = thisMessage.HasAttachments;
            if (messageHasAttachments) noOfAttachments = thisMessage.Attachments.Count();
            string isBodyHtml = //cant seem to implement this either
            Boolean domainblacklistResult = fn.CheckIfDomainBlacklisted(messageFrom);
            Boolean emailblacklistResult = fn.CheckIfEmailBlacklisted(messageFrom);

Upvotes: 0

Views: 161

Answers (1)

MadDev
MadDev

Reputation: 1150

To access information about the email message, you need to bind it as an EmailMessage, instead of as an Item. Example:

EmailMessage message = EmailMessage.Bind(service, thisMessage.Id);

Upvotes: 1

Related Questions