拆分电子邮件正文VB.NET

时间:2019-04-25 09:10:13

标签: vb.net email split exchangewebservices

因此,在EWS中,回复的电子邮件与原始电子邮件一起显示。

但就我而言,我只需要电子邮件中的最新回复即可。

例如:

来自:aaa@domain.com
发送:发送日期
到:bbb@domain.com

你好,谢谢你->只想参加这一部分

致谢,
A


来自:bbb@domain.com
发送:发送日期
到:aaa@domain.com

嗨,你好吗?

致谢,
B


粗体部分是我需要的唯一

这是我的代码的摘要:

    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

0 个答案:

没有答案