使用EWS托管API检索已发送的消息

时间:2017-07-05 12:04:54

标签: vb.net exchangewebservices ews-managed-api

我正在尝试使用EWS托管API发送消息,我需要确认消息已发送并注册一些信息(例如日期和时间已发送)。但是,我得到一个例外,如下所示。我的问题是:如何在发送消息后检索发送消息的EmailMessage对象?

非常感谢!

Private Sub NovaMensagemToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles NovaMensagemToolStripMenuItem.Click
    Dim em As New EmailMessage(serviceClient.Service)
    em.Subject = "Test"
    em.Body = "This is a test."
    em.ToRecipients.Add("mytestmail@test.com")
    em.SendAndSaveCopy(WellKnownFolderName.SentItems)
    em.Load() 'Exception: System.InvalidOperationException: This operation can't be performed because this service object doesn't have an Id.
    MsgBox(em.DateTimeSent)
End Sub

1 个答案:

答案 0 :(得分:1)

显然,只需在发送之前保存草稿:

Private Sub NovaMensagemToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles NovaMensagemToolStripMenuItem.Click
    Dim em As New EmailMessage(serviceClient.Service)
    em.Subject = "Test"
    em.Body = "This is a test."
    em.ToRecipients.Add("mytestmail@test.com")
    em.Save(WellKnownFolderName.Drafts) '<--- added this
    em.SendAndSaveCopy(WellKnownFolderName.SentItems)
    em.Load() 'no exception now
    MsgBox(em.DateTimeSent)
End Sub