如何在不同用户的 outlook 中打开新邮件?

How can I open new mail in outlook with different user?

我有用户 myuser 在 windows 中登录,我用其他用户打开程序。

我需要它然后我在 outlook 中打开新邮件它将使用我的用户打开它。我使用的代码是:

Outlook.Application App = new Outlook.Application();
        Outlook._MailItem MailItem = (Outlook._MailItem)App.CreateItem(Outlook.OlItemType.olMailItem);
        MailItem.To = BossName.Text;
        MailItem.CC = ClientName.Text;
        MailItem.Display(true);

在所需用户的上下文中启动您的应用程序,或者

  1. 您可以使用模拟:

WindowsIdentity.Impersonate Method

确保 outlook 没有 运行 在您的会话中。 Outlook 在一个会话中只能 运行 一次 - 因此不可能在一个 Windows-Session 中同时使用不同的 Outlook-MAPI-Session 登录。您总是需要重新打开 outlook。

  1. 多个 Outlook 配置文件

另一种方法是配置多个 Outlook 配置文件并通过 .net 启动 outlook 并传递配置文件名称。但这可能有点棘手,因为您总是必须检查 outlook 是否已经 运行 在不同的 profilecontext 中 - 因为如果 outlook 已经打开,Profile-Parameter 将被忽略。

class Sample
{
    Outlook.Application GetApplicationObject()
    {

        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. Or close Outlook to open a new instance with a desired profile
            application = Marshal.GetActiveObject("Outlook.Application") as Outlook.Application;
            //!! Check if the application is using the right profile - close & reopen if necessary
        }
        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("profilename", "", Missing.Value, Missing.Value);
            nameSpace = null;
        }

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

}
  1. 如果可能使用 EWS

另一种方法是使用 EWS-API (Exchange WebServices-API),但这需要有一个 Exchange 或 Office365 帐户。并且仅当您想在后台处理 outlook 项目时才有用(.Display() 是不可能的) 如果您使用的是 Exchange 帐户 (Office365),我更愿意这样做...... Get started with EWS Managed API client applications