Losing handle to MailItem when send

  • Thread starter Thread starter donald
  • Start date Start date
D

donald

If you access Outlook through COM-automation and create a new MailItem,
you lose access to it when it is send.

"The subject has been moved or deleted" or some such error message you
get, if you try to access any of the mails properties after it has been
send.

I know i need to keep track of the MailItem where it is using
MAPIFolder.Items.ItemAdd event on the "Sent Items" folder and add a
unique custom property to the message and then search for that message
in the "Sent Items" folder.

I got the ItemAdd and it find it but i need to check it is the right
message so how can i add a custom property to all the MailItem in
outlook?

Thanks

Donald
 
You should be able to use the Application_ItemSend event handler to add a custom property.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
I could do it with that yes but i would like to do it with ItemAdd
because i basic set it all up now. i am putting the custom property in
side Mileage but i can't read what is in Mileage i get a error about
late binding

this is my code:

Private Sub currentoutbox_ItemAdd(ByVal Item As Object) Handles
currentoutbox.ItemAdd

Dim subject As String
Dim Mileage As String

subject = Item.Subject

Try
Mileage = Item.Mileage
Catch ex As Exception
MsgBox(ex.ToString)
End Try

End Sub
 
Never, ever change items in the Outbox. Either change them in the Sent Items folder or use Application_ItemSend.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
i am chnaging that in the Sent Items

i have currentoutbox = _NameSpace.Folders.Item("MailBox -
XXXXXXXXXX").Folders("Sent Items").Items
 
But you're using the Add event on the OUtbox's Items collection:
Private Sub currentoutbox_ItemAdd(ByVal Item As Object) Handles
currentoutbox.ItemAdd

Never use that folder's ItemAdd event. Use the ItemAdd event in Sent Items or use Application_ItemSend.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
i am loss here

what folder do i do ItemAdd event on and what type do i have it on??

Donald
 
This statement in the snippet you posted suggests that you're trying to process items as they are added to the Outbox, although you don't show the derivation of your "currentoutbox" object:

Private Sub currentoutbox_ItemAdd(ByVal Item As Object) _
Handles currentoutbox.ItemAdd

Repeating: Never use the Outbox folder's ItemAdd event. Use the ItemAdd event for the Sent Items folder or use Application_ItemSend.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
Application.ItemSend event fires before the mesasge is first moved to the
Outbox and then to the Sent Items folder, so you you can safely add your
custom prop in that event handler.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 
Back
Top