问题
So, in EWS replied email is shown together along with the original email.
But in my case I just need the latest reply from the email.
For example :
From : aaa@domain.com
Sent : date sent
To : bbb@domain.com
Hi, hello, I'm fine thanks -> only want to take this part
Regards,
A
From : bbb@domain.com
Sent : date sent
To : aaa@domain.com
Hi, how are you?
Regards,
B
The bold parts is the ONLY THING I need.
Here is the snipped of my code :
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
'Initiate Connection to Exhcange Service (EWS)'
Dim service As New ExchangeService(ExchangeVersion.Exchange2007_SP1)
service.Credentials = New WebCredentials("email@domain.com", "email password")
service.TraceEnabled = True
service.TraceFlags = TraceFlags.All
service.AutodiscoverUrl("email@domain.com")
'Read Inbox'
Dim myMailBox As Mailbox = New Mailbox("email@domain.com")
Dim myFolder As FolderId = New FolderId(WellKnownFolderName.Inbox, myMailBox)
Dim myView As ItemView = New ItemView(100)
myView.OrderBy.Add(ItemSchema.DateTimeReceived,SortDirection.Descending)
'Result'
Dim results As FindItemsResults(Of Item) = service.FindItems(myFolder, myView)
'Show Result'
Dim ctr As Integer = 0
For Each mailitem In results
mailitem.Load()
If ctr = 0 Then
ctr += 1
HttpContext.Current.Response.Write("<br/>===============<br/>")
HttpContext.Current.Response.Write("Email No. " & ctr)
HttpContext.Current.Response.Write("<br/>===============<br/>")
HttpContext.Current.Response.Write(mailitem.Subject)
HttpContext.Current.Response.Write("<br/>===============<br/>")
HttpContext.Current.Response.Write(mailitem.Body.Text)
HttpContext.Current.Response.Write("<br/>===============<br/>")
End If
Next
HttpContext.Current.Response.End()
End Sub
End Class
来源:https://stackoverflow.com/questions/55845683/split-email-body-vb-net