5

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!

5
  • 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
    Commented Jul 21, 2011 at 21:16
  • @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
    Commented Jul 22, 2011 at 3:58
  • 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
    Commented Jul 22, 2011 at 14:06
  • 1
    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.
    – user50049
    Commented Jul 22, 2011 at 15:42
  • @Tim Post: Alright, I've updated my answer. I hope the scope it's clearer and what I tried and thought of. Thanks!
    – Bogdan
    Commented Jul 25, 2011 at 7:09

3 Answers 3

3

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

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.

3
  • I saw that article too, but thanks for looking into it. Unfortunately that info is for outlook 2000 and Microsoft changed completely the API for the interface items. Anyway currently I've built a PoC IMAP client using Mail.dll (lesnikowski.com/mail) and things are looking cool.
    – Bogdan
    Commented Aug 4, 2011 at 19:57
  • Good Deal! So this dll gives the functions? I saw the new API on Microsoft's site... is there an API for what you did?
    – Jeff
    Commented Aug 4, 2011 at 20:26
  • That library provides everything you need to create an email client (POP/IMAP/SMTP/SMIME/etc) and has great documentation. And it's priced reasonably.
    – Bogdan
    Commented Aug 5, 2011 at 7:27
0

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!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.