EWS body plain text

后端 未结 5 1234
盖世英雄少女心
盖世英雄少女心 2020-12-05 06:47

I use EWS to get exchange emails, but how can i get plain text from email body, without html?
Now i use this:

EmailMessage item = (EmailMessage)outbox         


        
相关标签:
5条回答
  • 2020-12-05 07:26

    The shortest way to do it is like this:

    item.Load(new PropertySet(BasePropertySet.IdOnly, ItemSchema.TextBody, EmailMessageSchema.Body));
    

    This has got the advantage that you get both, text-body and html-body.

    0 讨论(0)
  • 2020-12-05 07:28

    you can use

    service.LoadPropertiesForItems(findResults, itempropertyset);
    

    to load properties for all items

    0 讨论(0)
  • 2020-12-05 07:30

    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);
    
    0 讨论(0)
  • 2020-12-05 07:43

    In powershell:

        .........    
    $message = [Microsoft.Exchange.WebServices.Data.EmailMessage]::Bind($event.MessageData,$itmId)
    
    $PropertySet = New-Object Microsoft.Exchange.WebServices.Data.PropertySet([Microsoft.Exchange.WebServices.Data.BasePropertySet]::FirstClassProperties)
    $PropertySet.RequestedBodyType = [Microsoft.Exchange.WebServices.Data.BodyType]::Text
    $message.Load($PropertySet)
    $bodyText= $message.Body.toString()
    
    0 讨论(0)
  • 2020-12-05 07:47

    I had the same issue. All you have to do is set RequestedBodyType property of the property set you are using.

        PropertySet propSet = new PropertySet(BasePropertySet.IdOnly, EmailMessageSchema.Subject, EmailMessageSchema.Body);
        propSet.RequestedBodyType = BodyType.Text;
        var email = EmailMessage.Bind(service, item.Id, propSet);
    
    0 讨论(0)
提交回复
热议问题