Подтвердить что ты не робот

Обычный текст EWS

Я использую EWS для получения обменных писем, но как я могу получить обычный текст из тела электронной почты без html?
Теперь я использую это:

EmailMessage item = (EmailMessage)outbox.Items[i];
item.Load();
item.Body.Text
4b9b3361

Ответ 1

В PropertySet вашего элемента вам нужно установить RequestedBodyType в BodyType.Text. Вот пример:

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);

Ответ 2

В 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()

Ответ 3

У меня была такая же проблема. Все, что вам нужно сделать, это установить свойство RequestedBodyType свойства, которое вы используете.

    PropertySet propSet = new PropertySet(BasePropertySet.IdOnly, EmailMessageSchema.Subject, EmailMessageSchema.Body);
    propSet.RequestedBodyType = BodyType.Text;
    var email = EmailMessage.Bind(service, item.Id, propSet);

Ответ 4

вы можете использовать

service.LoadPropertiesForItems(findResults, itempropertyset);

для загрузки свойств для всех элементов

Ответ 5

Самый короткий способ сделать это:

item.Load(новый PropertySet (BasePropertySet.IdOnly, ItemSchema.TextBody, EmailMessageSchema.Body));

Это имеет то преимущество, что вы получаете как тело текста, так и html body