Я использую EWS для получения обменных писем, но как я могу получить обычный текст из тела электронной почты без html?
Теперь я использую это:
EmailMessage item = (EmailMessage)outbox.Items[i];
item.Load();
item.Body.Text
Я использую EWS для получения обменных писем, но как я могу получить обычный текст из тела электронной почты без html?
Теперь я использую это:
EmailMessage item = (EmailMessage)outbox.Items[i];
item.Load();
item.Body.Text
В 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);
В 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()
У меня была такая же проблема. Все, что вам нужно сделать, это установить свойство RequestedBodyType свойства, которое вы используете.
PropertySet propSet = new PropertySet(BasePropertySet.IdOnly, EmailMessageSchema.Subject, EmailMessageSchema.Body);
propSet.RequestedBodyType = BodyType.Text;
var email = EmailMessage.Bind(service, item.Id, propSet);
вы можете использовать
service.LoadPropertiesForItems(findResults, itempropertyset);
для загрузки свойств для всех элементов
Самый короткий способ сделать это:
item.Load(новый PropertySet (BasePropertySet.IdOnly, ItemSchema.TextBody, EmailMessageSchema.Body));
Это имеет то преимущество, что вы получаете как тело текста, так и html body