5
votes

I'm working on a little script in VBA that would allow me to automatically forward messages, including encrypted ones.

The only problem I have is removing the encryption programmatically.

I thought I could do it like this:

  • Open the message
  • unselect the Encrypt & Sign options
  • forward message

With this approach I don't know how to get a reference to the Encrypt & Sign buttons.

Here's the code that works for standard, non encrypted mails. I set this method as an "Email rule" for all incoming mails:

Sub test_macro(MyMail As MailItem)
    MyMail.Display
    'Need some API here to access the decrypt button    


    MyMail.Recipients.Add "[email protected]"
    MyMail.Recipients.Add "[email protected]"
    Item_Send (MyMail)


End Sub

Background

There's a requirement here to forward all incoming messages for a department address to certain people. Forwarding them encrypted causes all sorts of certificate issues between various versions of Outlook (2003/2007/2010/etc) since they all need to have the private key of the department address and that seem to conflict with their personal account certificate (I get all sort of erratic behavior, sometimes it works, sometimes not).

Alternative approaches

  • I realize that because of security restrictions the current approach will probably not work so I'm looking into alternatives. Maybe if I create a plugin for Outlook, will that give me access to some security API to decrypt incoming messages?

  • Create a POP client, fetch, manually decrypt the messages and forward it. This is probably the hardest approach since there are a lot of encryption formats/algorithms wich Outlooks supports by default.

Any other ideas? Thanks!

3
This sounds suspiciously like malware. Programmatically decrypting and forwarding messages isn't something you should be doing unless you're trying to do something malicious.Ken White
@Ken White, please don't jump to conclusions. There's a requirement here to forward all incoming messages for a department address to certain people. Forwarding them encrypted causes all sorts of certificate issues between various versions of Outlook (2003/2007/2010/etc) since they all need to have the private key of the department address and that conflicts with their personal account certificate...Bogdan
I didn't jump to any conclusion. I said it sounded suspicious (which it still does, until you explain it in your comment).Ken White
I'm quite sure you aren't doing nefarious things here .. but do you have perhaps a broken attempt at this to show? It would also really help if you explained your purpose in your question, comments do tend to vanish from time to time.Tim Post
@Tim Post: Alright, I've updated my answer. I hope the scope it's clearer and what I tried and thought of. Thanks!Bogdan

3 Answers

3
votes

I know this is an older thread, but for those interested, the correct way to programmatically toggle (enable or disable) sign and programmatically toggle encrypt (and also check for signature and encryption) is shown in the VBA article referenced below. This can also be done in .NET with minor adjustments

https://support2.microsoft.com/kb/2636465?wa=wsignin1.0

For example, the following C# .NET function can be used in Outlook 2007, 2010, 2013 to programmatically check if an email item is encrypted:

public static bool isEmailEncrypted(ref Outlook.MailItem mItem) {
        bool retVal = false;
        string PR_SECURITY_FLAGS = "http://schemas.microsoft.com/mapi/proptag/0x6E010003";
        long flags = (long)mItem.PropertyAccessor.GetProperty(PR_SECURITY_FLAGS);
        //need to do bitwise AND operation
        long bitwiseAND = flags & 1; //encrypted bit is the first bit
        if (bitwiseAND == 1) {
            retVal = true;
        }
        return retVal;
    }
0
votes

At fist I thought it had to be a method in the MailItem object, but there is no MailItem.Encrypt() function.

This took a while to find: http://support.microsoft.com/?kbid=279013

I do not think there is a way to do what you want the way you want, but perhaps you can use the info at that link to create a custom mail message form with a MailItem as input and have it send afterward.

0
votes

I ended up creating an IMAP email client using the excellent library Mail.dll. I highly recommend this for email stuff - great documentation, great support!