Andreas
Andreas

Reputation: 982

Encrypting BIG emails in Outlook cause Low Ressources Exception in C#

I am developing a tool, that encrypts emails with S/MIME in bulk within Outlook 2013. It works so far, but when I am trying to encrypt a REALLY BIG email (in the test case it was about 60MB raw). I get a COMException stating unsufficient ressources.

I can go around this, by working direktly with EWS and MimeKit (which works like a charm! Thank you @jstedfast), but I'd like to find a way to work in Outlook, for network traffic considerations. I know these changes will be synched to Exchange eventually, but during the process itself, it is independent of bandwidth.

I am also looking at MapiEx, but if there is an easier solution, than having yet another dependency (and with MFC too), I'd be happy! Maybe there are some settings, I'd have to make before.

A bit of code. The Exception it caught somewhere else.

public void String SetEncryption(MailItem mailItem)
{
    PropertyAccessor pa = null;
    try
    {
        pa = mailItem.PropertyAccessor;
        Int32 prop = (int)pa.GetProperty(_PR_SECURITY_FLAGS);
        Int32 newprop = prop | 1; 
        pa.SetProperty(_PR_SECURITY_FLAGS, newprop);
    }
    finally
    {
        Marshal.FinalReleaseComObject(pa);
        pa = null;
    }
}

Edit: The Exception is not coming, when the encryption is set, but when the result is saved, after the encryption is set.

SetEncryption(mailItem);
mailItem.Save();

Upvotes: 0

Views: 112

Answers (2)

Andreas
Andreas

Reputation: 982

I solved it myself. Since I had the problems in Outlook itself, I was trying MAPIEx to access the raw S/MIME Attachment in the email and de-/encrypt it using MimeKit/BouncyCastle.

The same problem occoured, but with a different error message, which lead me to the following site: ASN.1 value too large.

To sum it up: The Crypto API has two signatures. One which takes a byte array and one, which takes a stream. The first one has an arbitrary imposed (!!!) limit of 100 Million Bytes. Since the enveloped CMS has double base64 the ratio of this 100 MB is 9/16, which is round about 56 MB.

I assume, that Outlook uses the same API-Call and therefore has this limit. I know it is not a fact, but the evidence strongly supports this theory. :)

Upvotes: 1

Dmitry Streblechenko
Dmitry Streblechenko

Reputation: 66255

Check if KB 2480994 is installed: http://support.microsoft.com/kb/2480994

Upvotes: 0

Related Questions