Exchange EWS Получить тело письма

Я не могу получить тело сообщения из почтового ящика Exchange и в SQL Server. Я загружаю вещи неправильно?

От | К | Тематические поля из электронных писем обрабатываются и отправляются в SQL Server.

Любая помощь приветствуется.

Dim service As New ExchangeService(ExchangeVersion.Exchange2010_SP1)
    service.Credentials = New WebCredentials("Jim@Test.com", "jimpassword")
    service.AutodiscoverUrl("jim@dTest.com")

    Dim View As New ItemView(1000)
    View.OrderBy.Add(EmailMessageSchema.DateTimeReceived, SortDirection.Descending)
    Dim Inbox As Folder = Folder.Bind(service, WellKnownFolderName.Inbox)

    Dim findResults As FindItemsResults(Of Item) = service.FindItems(WellKnownFolderName.Inbox, New ItemView(1000))

    Dim emailPropSet As New PropertySet()
    emailPropSet.RequestedBodyType = BodyType.Text
    emailPropSet.BasePropertySet = BasePropertySet.FirstClassProperties

    If findResults.Count > 0 Then
        service.LoadPropertiesForItems(findResults.Items, New PropertySet(BasePropertySet.FirstClassProperties))
    End If

    For Each item As Item In findResults.Items

        Dim CurrentEmail As EmailMessage = item.Bind(service, item.Id, emailPropSet)
        CurrentEmail.Load(emailPropSet)


        '#### Grab Email Information
        Dim E_Body As String = CurrentEmail.Body.Text


        Dim ConnectionString As String
        Dim cnn As SqlConnection
        Dim cmd As New SqlCommand

        ConnectionString = "Data Source=localsql;Initial Catalog=TESTDB;Persist Security Info=True;User ID=sa;Password=Password123"
        cnn = New SqlConnection(ConnectionString)

        Try
            cnn.Open()
            MsgBox("Connection is Open ! ")
            cmd.Connection = cnn
            cmd.CommandText = "INSERT INTO Emails ([MessageID], [From], [To], [CC], [Subject], [Body], [Received], [Sent]) VALUES ('" & E_ID & "', '" & E_From & "', '" & E_To & "', '" & E_ID & "', '" & E_Subject & "', '" & E_Body & "', '" & E_ID & "', '" & E_ID & "')"
            cmd.ExecuteNonQuery()
            MsgBox("Data is Successfully Inserted! ")
            cnn.Close()

        Catch ex As System.Data.SqlClient.SqlException

        Finally

        End Try
    Next

0 ответов

Другие вопросы по тегам