2012-06-28 4 views
25

교환 이메일을 받기 위해 EWS를 사용하지만 html이 아닌 이메일 본문에서 일반 텍스트를 가져 오는 방법은 무엇입니까? 당신이 BodyType.Text에 RequestedBodyType를 설정해야합니다 당신의 품목의 PropertySet에서EWS 본문 일반 텍스트

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

답변

57

:
지금 나는이를 사용합니다. 다음 예는 다음과 같습니다

.........  
$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

감사합니다. – JNM

+7

이 작업을 제대로 수행하려면 Property.FindItems() 및 item.Load()에 PropertySet을 사용해야합니다. – Dave

+0

Microsoft.Exchange.WebServices.Data.ServiceObjectPropertyException을 수행 할 때이 예외가 발생합니다. – kolexinfos

3

모든 항목 PowerShell에서

+0

값을 읽거나 항목 고유 ID를 알고있는 경우이 속성을로드하거나 할당해야합니다 :'PropertySet plainTextPropertySet = new PropertySet (BasePropertySet. FirstClassProperties) { RequestedBodyType = BodyType.Text, }; EmailMessage emailMessage = EmailMessage.Bind (service, uniqueId, plainTextPropertySet); 문자열 body = emailMessage.Body.Text; ' – SamFlushing

5

속성을로드

service.LoadPropertiesForItems(findResults, itempropertyset); 

를 사용할 수 있습니다. 사용중인 속성 세트의 RequestedBodyType 속성을 설정하면됩니다.

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

이 경우'$ event'는 무엇입니까 ?? '$ itmId' ??? - EmailMessage가 있는데 마지막 4 줄과 똑같은 코드를 사용하고 있지만 여전히 plaintext 대신 HTML을 반환합니다. 내가 알아 내면 돌아올 것을 기억하려고 노력할 것이다 : - / –

4

저도 같은 문제를 가지고 :

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

할 최단 식으로이 같다 :

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

이것은 텍스트 본문과 html 본문을 모두 얻을 수 있다는 장점이 있습니다.