Split Email Body VB.NET

你说的曾经没有我的故事 提交于 2019-12-11 16:04:56

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!