Error when saving MailItem or deleting Attachment

Error when saving MailItem or deleting Attachment

Post by Michael Ki » Wed, 29 Oct 2003 22:52:20


I have an addin that catches outgoing messages and converts office documents
to html, removes the original attachment and attaches the coverted html.
Before I do the conversion I call Item.Save to make sure I can leave a valid
email in the draft folder if something crashes. In Outlook XP if there are
non-office documents attached after office documents (i.e. a .doc then a
.txt) when I make the call to delete the old attachments I get an "Object
required" error. I have debugged it to the point that I know that using
save (either manually or programatically) before doing the deletes causes
the error message.

In my debugging I noticed that saving the message manually results in the
attachments being reordered placing the office documents at the end of the
list of attachments. To see this you have to close the in-progress email
and reopen it from the drafts folder. With the documents in this order
(non-office docs first, office docs last) everything works fine.

Note that I am seeing this behavior only in 2002/XP SP2 and not in 2003 or
2000 or 2002 before SP2
and that the bug occurs before any of the conversion takes place.

I can reproduce the problem on any Windows OS running Outlook XP (latest SP,
security patches, etc), Outlook or Word as editor.

The steps to reproduce the error are simple:

1. Create a COM Addin with the following code below
2. Start Outlook XP with Service Pack 2 installed and COM AddIn loaded
3. Create a new email
4. Add two attachments: and Excel document (or other Office document) and a
Text document (or other non-Office document). Attachment must be added
Office document first and non-Office document second
5. Click the SAVE button on the command bar
6. Click the SEND button

In the ItemSend event you will receive an 'Object Required' error.

'''Code Example

Option Explicit

Implements IDTExtensibility2

Public WithEvents mobjApplication As Outlook.Application

Private Sub IDTExtensibility2_OnAddInsUpdate(custom() As Variant)
' this sub is required, even though we do nothing within it
End Sub

Private Sub IDTExtensibility2_OnBeginShutdown(custom() As Variant)
' this sub is required, even though we do nothing within it
End Sub

Private Sub IDTExtensibility2_OnConnection(ByVal Application As Object, _
ByVal ConnectMode As
AddInDesignerObjects.ext_ConnectMode, _
ByVal AddInInst As Object,
custom() As Variant)

Set mobjApplication = Application
End Sub

Private Sub IDTExtensibility2_OnStartupComplete(custom() As Variant)
' this sub is required, even though we do nothing within it
End Sub

Private Sub mobjApplication_ItemSend(ByVal Item as Object, Cancel as
Boolean)
objItem.Save 'This is where the error occurs
End Sub
 
 
 

Error when saving MailItem or deleting Attachment

Post by Michael Ki » Thu, 30 Oct 2003 02:37:54

Small correction to the ItemSend event.

objItem.Save should be Item.Save



documents
valid
are
SP,
a

 
 
 

Error when saving MailItem or deleting Attachment

Post by Michael Ki » Thu, 30 Oct 2003 23:57:22

After some further investigation I can add the following...

This problem only occurs when editing in HTML or Plain Text format, but not
when editing in Rich Text.




documents
valid
are
SP,
a