views:

12

answers:

2

Background: I'm working on an Outlook addin which adds an attachment to outgoing emails. Support is required for all versions of Outlook.

When a MailItem has been signed with a digital signature, adding an attachment to this mailItem generally fails unless you save the mail item. This removes the signature from mailitem. To me, this is somewhat expected behaviour. Nothing weird here.

The problem is when the user turns digital signatures on (whether through the UI or as a Outlook default behavior) and then turns it off again. The MailItem is no longer signed but it still behaves as if it is -- we're unable to add an attachment to this email.

I found a newsgroup post which might explain why; it appears that objects retrieved through the outlook API aren't the actual objects.

http://www.tech-archive.net/Archive/Development/microsoft.public.win32.programmer.messaging/2006-02/msg00000.html

At the moment, I've given up trying to fix this problem nicely; saving the MailItem to a temporary file appears to fix this however for performance reasons we'd like to only save when a MailItem has transitioned from signed to unsigned. Another acceptable alternative is to detect whether digital signatures has been enabled by default or not. Though there is a registry entry related to the default setting of a digital signature, it is merely a suggestion and does not reflect accurately whether the email would have been signed by default or not.

Any ideas?

A: 

Turns out that you can use EMAPI in C++ to call IMessagePtr->SaveChanges(), which seems to work quite nicely. Unfortunately, you can't access this in C#.

MauriceL
A: 

You can use redemption api library to call that method from C#.

Also have you tried creating a PInvoke signature from the extended mapi dll?

Anonymous Type
calling from redemption didn't actually work which was surprising. The PInvoke is a good idea; but we've already got a c++ wrapper in play so may as well just call it there :)
MauriceL