c# outlook open existing instance and reply to email

孤街浪徒 提交于 2020-01-03 05:00:07

问题


c# outlook open existing instance and get list of opened outlook windows to compose reply to of chosen window.

i am able to get outlook's existing instance but not sure how to approach its child windows and set reply to with existing email rather creating new mailitem

public static Outlook.Application OutlookInstance { get { Outlook.Application application = null;

            // Check whether there is an Outlook process running.
            if (Process.GetProcessesByName("OUTLOOK").Count() > 0)
            {

                // If so, use the GetActiveObject method to obtain the process and cast it to an Application object.
                application = Marshal.GetActiveObject("Outlook.Application") as Outlook.Application;
            }
            else
            {

                // If not, create a new instance of Outlook and log on to the default profile.
                application = new Outlook.Application();
                Outlook.NameSpace nameSpace = application.GetNamespace("MAPI");
                nameSpace.Logon("", "", Missing.Value, Missing.Value);
                nameSpace = null;
            }

            // Return the Outlook Application object.
            return application;
        }
    }

回答1:


It looks like you are interested in the ActiveInspector method which return the topmost Inspector object on the desktop. Use this method to access the Inspector object that the user is most likely to be viewing. If no inspector is active, returns null (Nothing in VB.NET).

Also you may find the Inspectors property of the Application class helpful. It returns an Inspectors collection object that contains the Inspector objects representing all open inspectors.

 Dim myInspectors As Outlook.Inspectors  
 Dim x as Integer 
 Dim iCount As Integer 
 Set myInspectors = Application.Inspectors 
 iCount = Application.Inspectors.Count 
 If iCount > 0 Then 
   For x = 1 To iCount 
     MsgBox myInspectors.Item(x).Caption 
   Next x 
 Else 
   MsgBox "No inspector windows are open." 
 End If 

If you need to get the currently selected items in the Outlook Explorer window use the Selection object. See How to: Programmatically Determine the Current Outlook Item for more information.



来源:https://stackoverflow.com/questions/30579056/c-sharp-outlook-open-existing-instance-and-reply-to-email

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!