Dealing with attachments in Outlook is a bit like entering an Ultimate Fighting match against a professional half-octopus, half-eel. It really doesn't matter what style of fighting you choose, the octo-eel is guaranteed to take you down more than once in the match, and there's really no telling whether you have a chance at winning.
An app that I'm working on deals with attachments in Outlook, more specifically, it deals with Office format attachments, so we're talking about DOC, XLS, and PPT files (and about 2 dozen other *X and *M formats introduced in Office 07).
Anything else (like BMPs, TXT files, etc) are supposed to pass on through like yesterday's iceberg salad.
However, astute customers noticed that, in some cases, the order of the attachments could change at times. If you had numerous attachments to your email, and you intended on them being in a particular order, that might not go over well.
Now, you might think, with such a nicely laid out object model as Outlook's, that preserving the order of attachments in a message would be trivial. Hell, you might even thing you could simply replace one attachment with another, simply by using a replace method or somesuch.
And you'd be wrong.
There's no replace method, unlike GroupWise. And the ATTACHMENTS.ADD method doesn't allow you to specify an ordinal. It does allow you to specify a position, but that value is only used to indicate the character position of the attachment in an RTF format email. If the email format is plain text, or HTML, the position isn't used at all.
Then there's this jewel from the MSDN documentation on the add method.
To ensure consistent results, always save an item before adding or removing objects in the Attachments collection of the item.
Special.
Add to all of that the fact that Word can also be used as the email editor (albeit in approximately the same capacity as the built-in Outlook RTF editor from what I can tell), and you have a whole lot of arms to fight with on this octo-eel.
The bottom line however, turns out to be relatively simple.
It sounds more complicated than it is.
If you get any part of it wrong, you'll know pretty quick. Usually, the attachments will end up in the sent email reversed in order. Worse case, some will end up missing.
One final trick. Testing all this can be a real pain, but you can make it a little easier.
Set up Outlook with POP accounts only (don't use Exchange for this). Then set it to NOT send email on startup:
Anything you send will end up in the outbox, where you can examine it, use it for debugging, drag it back to the inbox to attempt a resend, or delete it. And from what I can tell, whatever ends up in the outbox is what would go. There's no additional processing done after that.
Plus, you don't even have to use a legitimate TO address, anything that looks like an email address will work.
Believe it or not, I actually like Outlook, despite it's, uh, quirks? It's been my email system since about 97. I've never had a corrupted PST file, never lost an email (that I didn't unintentionally delete with Shift-Del), and never gotten an email-born virus.
Now, excuse me, I have some serious knocking to attend to.
Remember Me
a@href@title, b, i, strike, strong
Page rendered at Saturday, July 31, 2010 6:41:00 AM (Central Standard Time, UTC-06:00)
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.