How can I read out the receiver and sender in the Reading Pane in Outlook with VB.net or C#

Ulrich Eul 26 Reputation points
2021-03-24T08:35:08.487+00:00

How can I read out the receiver and sender in the Reading Pane in Outlook with VB.net or C#. It goes in a new window in which a new mail is created with

objOL = CreateObject ("Outlook.Application")
MsgBox ("objOL.ActiveInspector.CurrentItem.To:" & objOL.ActiveInspector.CurrentItem.To

It doesn't work in the reading pane (docked window).

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,266 questions
0 comments No comments
{count} votes

Accepted answer
  1. Castorix31 81,726 Reputation points
    2021-03-24T17:40:15.247+00:00

    Thsi test in c# works for me on an opened Outlook instance (Outlook 2016, Windows 10) =>

    Microsoft.Office.Interop.Outlook.Application oOutlookApp= null;
    if (Process.GetProcessesByName("outlook").Count() > 0)
    {
        oOutlookApp = Marshal.GetActiveObject("Outlook.Application") as Microsoft.Office.Interop.Outlook.Application;
        if (oOutlookApp != null)
        {
            Microsoft.Office.Interop.Outlook.MAPIFolder selectedFolder = oOutlookApp.ActiveExplorer().CurrentFolder;
            if (oOutlookApp.ActiveExplorer().Selection.Count > 0)
            {
                Object selObject = oOutlookApp.ActiveExplorer().Selection[1];
                if (selObject is Microsoft.Office.Interop.Outlook.MailItem)
                {
                    Microsoft.Office.Interop.Outlook.MailItem mailItem = (selObject as Microsoft.Office.Interop.Outlook.MailItem);
                    string sSender = mailItem.SenderName;
                    string sTo = mailItem.To;
                    System.Windows.Forms.MessageBox.Show("Sender : " + sSender + Environment.NewLine + "To : "  + sTo + Environment.NewLine, "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }
    }
    
    0 comments No comments

7 additional answers

Sort by: Newest
  1. Ulrich Eul 26 Reputation points
    2021-03-27T14:58:38.477+00:00

    Hello Castorix31,

    thank you very much for your help :), it's run fine. A last question please, how can I degug the code so that I can see that the refrence from the window in Outlook is in example Explorer.ActiveInlineResponse?

    0 comments No comments

  2. Ulrich Eul 26 Reputation points
    2021-03-27T10:53:16.623+00:00

    Hello Castorix31,

    how must I change your Code form above. I try it with oOutlookApp.ActiveExplorer().ActiveInlineResponse; but I receive everytimes errors. Must I use the code var resp = oOutlookApp.ActiveExplorer().ActiveInlineResponse; in connection with oOutlookApp = Marshal.GetActiveObject("Outlook.Application") as Microsoft.Office.Interop.Outlook.Application;?
    Sorry, I am not the specialist in c#.


  3. Ulrich Eul 26 Reputation points
    2021-03-27T08:48:47.197+00:00

    But my problem that I can't read receiver and sender in the Reading Pane in Outlook with VB.net or C# is not solved. In the appendix I am attaching a screenshot in which I present the problem again. In the picture you see the red arrows in the reading pane/area from outlook. The reading pane/area open when you click in the reading pane/area on the button Reply (I think that is the Name from the button in an English MS-Outlook). I want read the Adress from Sender (Von) and the recipient/receiver(An) in the reading pane/area. If you click the Reply button in the reading area, no new window will open. The answer mail is answered directly in the main Outlook window. I want know, what is the refrence from the reading pane/area in Visual Studio?

    82005-screenshot-outlook.jpg


  4. Ulrich Eul 26 Reputation points
    2021-03-26T15:09:14.13+00:00

    Hello Castorix31,

    thank you very much for your tip with search for "TYPE_E_CANTLOADLIBRARY" interop. I found, that the reason can be, that the MS-Office is corrupt, it was true, I repair my MS-Office an now it's run :).

    1 person found this answer helpful.
    0 comments No comments