Losing handle to MailItem when send

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
 
S

Sue Mosher [MVP-Outlook]

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
 
D

donald

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
 
S

Sue Mosher [MVP-Outlook]

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
 
D

donald

i am chnaging that in the Sent Items

i have currentoutbox = _NameSpace.Folders.Item("MailBox -
XXXXXXXXXX").Folders("Sent Items").Items
 
S

Sue Mosher [MVP-Outlook]

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
 
D

donald

i am loss here

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

Donald
 
S

Sue Mosher [MVP-Outlook]

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
 
D

Dmitry Streblechenko

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top