Reputation: 1269
EDIT #2---- It compiles fine, but I get a debug error of: The URL property on the ExchangeService must be set on this line On This Line of Code 'FindItemsResults findResults = service.FindItems(WellKnownFolderName.Inbox, new ItemView(128));' End EDIT #2 ----
EDIT --- Ugh -- I didn't realize I needed 10 rep points to post an image...let me give a few of the errors.
1) Type or namespace 'FindItemsResults' could not be found
2) Type or namespace name 'Item' could not be found
3) The name 'service' does not exist in the current context
4) Type or namespace 'ItemView' could not be found
EDIT ----
I saw the post here -- How to get email body, receipt, sender and CC info using EWS? and was looking at this code sampling
public class MailItem
{
public string From;
public string[] Recipients;
public string Subject;
public string Body;
}
public MailItem[] GetUnreadMailFromInbox()
{
FindItemsResults<Item> findResults = service.FindItems(WellKnownFolderName.Inbox, new ItemView(128));
ServiceResponseCollection<GetItemResponse> items =
service.BindToItems(findResults.Select(item => item.Id), new PropertySet(BasePropertySet.FirstClassProperties, EmailMessageSchema.From, EmailMessageSchema.ToRecipients));
return items.Select(item =>
{
return new MailItem()
{
From = ((Microsoft.Exchange.WebServices.Data.EmailAddress)item.Item[EmailMessageSchema.From]).Address,
Recipients = ((Microsoft.Exchange.WebServices.Data.EmailAddressCollection)item.Item[EmailMessageSchema.ToRecipients]).Select(recipient => recipient.Address).ToArray(),
Subject = item.Item.Subject,
Body = item.Item.Body.ToString(),
};
}).ToArray();
}
But am getting multiple compile errors. How is a very clear instructions way to read the body of an email using C#?
Upvotes: 4
Views: 2558
Reputation: 4849
Think you are missing a reference to MS Exchange assembly Microsoft.Exchange.WebServices.dll
or the using statement using Microsoft.Exchange.WebServices.Data;
For (3)
you will need to declare and initialise the service object as shown in the linked question.
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010);
Note : You can get the assemblies from Microsoft Exchange Web Services Managed API 2.0
and MSDN docs to get started + Code samples
Upvotes: 1