0

I'm using Exchange Service in c# to receive an email.

I'm using the following code:

var service = new ExchangeService
    {
        Credentials = new WebCredentials("somename", "somepass"),
        Url = new Uri("someurl")
    };
FindItemsResults <Item> findResults = service.FindItems(WellKnownFolderName.Inbox,new ItemView(1));
var item = findResults.Items[0];
item.Load();
return item.Body.Text;

It returns body in html. Is there any way i could get text only instead of html, i don't need html tags. Or should i parse it?

Thanks for any input.

2
  • If there's no native solution, see stackoverflow.com/questions/19523913/… Commented Nov 13, 2015 at 21:51
  • i was hoping for a Exchange solution, i thought i was missing some parameter. But anyway thanks Commented Nov 13, 2015 at 21:55

2 Answers 2

4

This worked for me.

var service = new ExchangeService
{
    Credentials = new WebCredentials("somename", "somepass"),
    Url = new Uri("someurl")
};

var itempropertyset = new PropertySet(BasePropertySet.FirstClassProperties)
{
    RequestedBodyType = BodyType.Text
};

var itemview = new ItemView(1) {PropertySet = itempropertyset};
var findResults = service.FindItems(WellKnownFolderName.Inbox, itemview);
var item = findResults.FirstOrDefault();
item.Load(itempropertyset);
Console.WriteLine(item.Body);
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks guys, i will accept this one, since it's not an example but works right away.
4

"In the PropertySet of your item you need to set the RequestedBodyType to BodyType.Text. Here's an example:"

PropertySet itempropertyset = new PropertySet(BasePropertySet.FirstClassProperties);
itempropertyset.RequestedBodyType = BodyType.Text;
ItemView itemview = new ItemView(1000);
itemview.PropertySet = itempropertyset;

FindItemsResults<Item> findResults = service.FindItems(WellKnownFolderName.Inbox, "subject:TODO", itemview);
Item item = findResults.FirstOrDefault();
item.Load(itempropertyset);
Console.WriteLine(item.Body);

Citated from this answer.

1 Comment

It seems we used the same source :) You beat me. Hehe

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.