none
The MailItem Object Disappears After Calling the Send() Method. RRS feed

  • Question

  • Hi all,

    I've spent hundreds of hours scrubbing these forums, but as far as I can remember, this is the first question I've ever posted. :)

    I'm writing a small application in VB.NET that sends an e-mail on behalf of a user to facilitate my organization's use of a new e-faxing system. At the end of the program, I want to verify that that the message has actually been sent through Outlook/Exchange, so I do this:

    if mailMsg.Sent Then
     ' Wait for while, then talk to the user.
    End If
    
    

    But I get the following message:

    "COMException was unhandled"

    "The item has been moved or deleted."

    If I add a button to my project to check run the same check (if mailMsg.Sent) at will (before the message is sent), it just reports "False" (which is what I expect).

    I tried adding the "BeforeDelete" and "Unload" event handlers, but neither of them fire after the message is sent. My goal is to hold the object open long enough for me to verify the "Sent" property as true, report it to the user, and then destroy the object myself.

    I'm running on 32 bit Office 2013 on top of 64 bit Windows 8. But I tried this on 32 bit Office 2013 on 64 bit Windows 7 as well and got the same result.

    If you guys have insights into this, I would really appreciate it!

    --
    Steve

    Tuesday, March 19, 2013 10:29 PM

Answers

  • Hi Steve,

    Why don't you use the "Send" event ?

    Maybe something like this:

    Private Sub mailMsg_ItemSend(ByVal Item As Object, Cancel As Boolean)

    'email sent, do something

    End Sub

    Wednesday, March 20, 2013 9:15 PM
  • Don't forget the "WithEvents" keyword when defining your mail object.
    Wednesday, March 20, 2013 9:17 PM

All replies

  • Hi Steve,

    Why don't you use the "Send" event ?

    Maybe something like this:

    Private Sub mailMsg_ItemSend(ByVal Item As Object, Cancel As Boolean)

    'email sent, do something

    End Sub

    Wednesday, March 20, 2013 9:15 PM
  • Don't forget the "WithEvents" keyword when defining your mail object.
    Wednesday, March 20, 2013 9:17 PM
  • Hi Steve,

    I temporarily marked the replies as answers. You can unmark them if they provides no help.

    Please feel free to let us know if you need any further help.

    Have a nice day.


    Quist Zhang [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, March 28, 2013 3:26 AM
    Moderator