Reputation: 2732
I'm trying to send a message using EWS Managed API, and I need to confirm message was sent and register some info (ex. the date & time it was sent). However, I get an exception as shown below. My question is: how can I retrieve the EmailMessage
object for the sent message, after it was sent?
Thank you very much!
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("[email protected]")
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
Upvotes: 0
Views: 278
Reputation: 2732
Apparently, all it takes is to save a draft before sending:
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("[email protected]")
em.Save(WellKnownFolderName.Drafts) '<--- added this
em.SendAndSaveCopy(WellKnownFolderName.SentItems)
em.Load() 'no exception now
MsgBox(em.DateTimeSent)
End Sub
Upvotes: 1