Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Outlook add-in get selected emails

I want to get all selected emails in my Outlook 2010 add-in. I found this MSDN tutorial, but I am a beginner at C#, and I don't quite understand this line of code: Object selObject = this.Application.ActiveExplorer().Selection[3];

I believe Selection[] is something like overridden operator, indexer in C#. But, is there any way to see implementation of it? If I go through the code, I only see interfaces but not implementations. So I don't know the structure of the Selection object. What is really behind the operator [].

Also, why do the selected items begin at index 1 and not 0?

like image 619
B.Gen.Jack.O.Neill Avatar asked Feb 11 '13 13:02

B.Gen.Jack.O.Neill


1 Answers

I know it's a little late but this question ranks highly in search engines. Here is the solution I use to get selected emails in Outlook Interop:

internal static IEnumerable<MailItem> GetSelectedEmails()
{
     foreach (MailItem email in new Microsoft.Office.Interop.Outlook.Application().ActiveExplorer().Selection)
     {
          yield return email;
     }
}
like image 114
jmdon Avatar answered Sep 24 '22 20:09

jmdon