我正在尝试使用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
答案 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