Get attached message object in Outlook 2013

Receiving a currently open new email message (if it is not installed from the main Outlook window) requires the following code:

Outlook.Application oApp = new Outlook.Application();
Outlook.Inspector inspector = oApp.ActiveInspector();
item = inspector.CurrentItem;
Outlook.MailItem oMsg = item as Outlook.MailItem;

How do you do this when a new message is docked in the main Outlook window? This happens when the user clicks the Reply button in the message they are currently viewing.

+4
source share
1 answer

If you want to return a new message as an object (for example Outlook.MailItem), you should try the following:

Outlook.Application oApp = new Outlook.Application();
Outlook.MailItem oMsg = explorer.GetType().InvokeMember("ActiveInlineResponse",
    System.Reflection.BindingFlags.GetProperty |
    System.Reflection.BindingFlags.Instance |
    System.Reflection.BindingFlags.Public, null, explorer, null) as Outlook.MailItem;

You should be able to attach the file to the currently attached Outlook message as needed.

+2
source

Source: https://habr.com/ru/post/1546078/


All Articles