Error when saving MailItem or deleting Attachment

M

Michael King

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
 
M

Michael King

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.
 

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