How to read digitally signed/encrypted emails

Add-in Express™ Support Service
That's what is more important than anything else

How to read digitally signed/encrypted emails
 
Utkarsh




Posts: 9
Joined: 2012-12-21
Hi Team,

I would like to read all the emails in the selected folder in Outlook. I have followed many examples in your blog and I am able to read the email. But the add-in throws the COM error when trying to read the signed email. I tried following following approaches but in vain.

1. Get the ItemType of MailItem (MSDN link for ItemType)
In the above case it will be either IPM.Note.Secure or IPM.Note.Secure.Sign.

Can you please let me know if there is any other way or better approach using ADX?
An example would be helpful.

Thanks in advance.
Regards,
Utkarsh
http://www.utkarshonline.com
Posted 23 Dec, 2012 23:27:22 Top
Andrei Smolin


Add-in Express team


Posts: 16803
Joined: 2006-05-11
Hi Utkrash,

I'm sorry, my previous message was intended for some other post. I'm sorry for sending it to you.

What code line produces the exception?

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 24 Dec, 2012 04:14:17 Top
Utkarsh




Posts: 9
Joined: 2012-12-21
Andrei Smolin writes:
What code line produces the exception?


Hi Andrei,

I have pasted the code below. Basically it is not doing anything special, but as soon as it encounters an signed email it throws the null error at it is not able to cast it to MailItem

Code:

Outlook.NameSpace nameSpace = OutlookApp.GetNamespace("MAPI");
            Outlook.MAPIFolder folderInbox = nameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox); 

            var currentFolder = OutlookApp.ActiveExplorer().CurrentFolder;
            Debug.WriteLine(currentFolder.Name);

            var itemsCount = currentFolder.Items.Count;

            for (int i = 1; i <= itemsCount; i++)
            {
                _MailItem mailItem = currentFolder.Items.Item(i) as _MailItem;
                Debug.WriteLine(mailItem.SenderName);
            }

            if (folderInbox != null) // Inbox 
            {
                System.Windows.Forms.MessageBox.Show(folderInbox.Name);
                Marshal.ReleaseComObject(folderInbox);
            }
            if (nameSpace != null) Marshal.ReleaseComObject(nameSpace);
Regards,
Utkarsh
http://www.utkarshonline.com
Posted 24 Dec, 2012 07:22:05 Top
Utkarsh




Posts: 9
Joined: 2012-12-21
Hi Andrei,

Please do not investigate this. There was some silly mistake at my end in the code. I have now added a null check to verify whether cast is successful. It is working fine.

Thanks for your support.
Regards,
Utkarsh
http://www.utkarshonline.com
Posted 24 Dec, 2012 08:40:07 Top
Andrei Smolin


Add-in Express team


Posts: 16803
Joined: 2006-05-11
Hi Utkarsh,

You cannot read an encrypted email programmatically because this would compromise the whole idea of encrypting.

I suppose the reasoning can be applied to digitally signed emails I've googled enough to conclude that you cannot read digitally signed emails too.

The page below and the pages it points is actually an essence of what I've been able to find:

http://www.outlookbanter.com/outlook-vba/7324-vb-macro-fails-digitally-signed.html

Hope this helps.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 24 Dec, 2012 08:42:14 Top
Utkarsh




Posts: 9
Joined: 2012-12-21
Hi Andrei,

I went through the link you shared. However, I have 2 questions.

1. I do not want to read the body of the signed email. I just want the sender email. Even this is not possible?
2. I do have the certificates installed on my local machine (certificates are provided by my employer). Even then it means that I cannot read the email?
Regards,
Utkarsh
http://www.utkarshonline.com
Posted 24 Dec, 2012 09:22:55 Top
Andrei Smolin


Add-in Express team


Posts: 16803
Joined: 2006-05-11
Hi Utkarsh,

I don't have answers to your questions. I suggest that you ask them at http://social.msdn.microsoft.com/Forums/en-US/outlookdev/threads. You'll get an answer if your post attracts attention of Ken Slovak and/or Dmitry Streblechenko.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 24 Dec, 2012 09:28:21 Top
Utkarsh




Posts: 9
Joined: 2012-12-21
Not a problem Andrei, thanks a lot for your help!
Regards,
Utkarsh
http://www.utkarshonline.com
Posted 24 Dec, 2012 09:55:54 Top