Solved

Exchange Web Services (EWS) VB.NET

Posted on 2014-11-05
2
557 Views
Last Modified: 2014-11-05
Morning,

I am creating a program that integrates with an Exchange Mailbox for Processing.

I wish to remove the part of the process that requires Outlook to be open a server and processing rules, so I have turned to using EWS.

The problem I have am having is return the 'FROM' field.

My code below I am able to connect to my Exchange Server and return the Category, To Field etc. perfectly fine, yet unable to return the From.

A lot of the documentation out there is written in C# of which i have NO experience.

Anyone pointing me in the right direction would be grand.

My Code:

        Dim exch As ExchangeService = New ExchangeService(ExchangeVersion.Exchange2007_SP1)
        Dim Uri As Uri

        Uri = New System.Uri("https://server/EWS/Exchange.asmx")
        exch.Url = Uri
        exch.UseDefaultCredentials = False
        exch.Credentials = New System.Net.NetworkCredential("ACCOUNT", "PASSWORD", "DOMAIN")

        exch.ImpersonatedUserId = New ImpersonatedUserId(ConnectingIdType.PrincipalName, "itprocessing@hq.freshinsurance.co.uk")

        ServicePointManager.ServerCertificateValidationCallback = AddressOf ValidateRemoteCertificate

        Dim iv As ItemView = New ItemView(10) ' return first 10 pages
        iv.Traversal = ItemTraversal.Shallow

        Dim InboxItems As FindItemsResults(Of Item) = Nothing

        InboxItems = exch.FindItems(WellKnownFolderName.Inbox, iv)

        For Each i As Item In InboxItems

            Console.WriteLine(i.Subject)
            Console.WriteLine(i.Categories)
            Console.WriteLine(i.DisplayTo)
            Console.WriteLine(i.HasAttachments)

            Dim strCat As String = i.Categories.ToString
        Next

Open in new window

0
Comment
Question by:Lynchie435
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 23

Accepted Solution

by:
Snarf0001 earned 500 total points
ID: 40423752
FindItems is a generic method that's used for various different actual objects, not just email.
When you're getting it from WellKnownFolderName.Inbox, it will actually return objects that are type "EmailMessage", which does have the From address, you just have to cast it first.

DirectCast(i, EmailMessage).From

Open in new window

0
 

Author Closing Comment

by:Lynchie435
ID: 40423828
Hi Snarf0001,

That doesn't appear to  the case as its Blank.

However you put me on the right track and it was

Console.WriteLine(DirectCast(i, EmailMessage).Sender.Name)

Open in new window


That i was looking for :)

Cheers,

James
0

Featured Post

Automating Your MSP Business

The road to profitability.
Delivering superior services is key to ensuring customer satisfaction and the consequent long-term relationships that enable MSPs to lock in predictable, recurring revenue. What's the best way to deliver superior service? One word: automation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Journaling 2 11
PowerShell:  foreach where object notmatch? 17 76
Exchange server take over 4 51
How to use File,History in Excel 2016 for Windows? 5 38
MS Outlook is a world-class email client application that is mainly used for e-communication globally.  In this article, we will discuss the basic idea about MS Outlook, its advanced features, and types of MS Outlook File formats.
A list of top three free exchange EDB viewers that helps the user to extract a mailbox from an unmounted .edb file and get a clear preview of all emails & other items with just a single click on mailboxes.
In this video we show how to create an Accepted Domain in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Mail Flow >> Ac…
To show how to create a transport rule in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Mail Flow >> Rules tab.:  To cr…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question