【问题标题】:How can I open new mail in outlook with different user?如何使用不同的用户在 Outlook 中打开新邮件?
【发布时间】:2015-05-06 11:45:44
【问题描述】:

我有用户 myuser 登录 windows,我用 otheruser 打开程序。

我需要它,然后我在 Outlook 中打开新邮件,它将使用 myuser 打开它。我正在使用的代码是:

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);

【问题讨论】:

  • 您可以手动操作吗?
  • 是的。每个人都可以通过按 shift+rightmouseclick 并为任何程序选择不同的用户来完成。
  • 哇...你能发布一个屏幕截图吗?

标签: c# winforms outlook windows-authentication


【解决方案1】:

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

  1. 您可以使用模拟:

WindowsIdentity.Impersonate Method

确保 Outlook 尚未在您的会话中运行。 Outlook 只能在一个会话中运行一次 - 因此不可能同时在一个 Windows 会话中使用不同的 Outlook-MAPI 会话登录。您总是必须重新打开 Outlook。

  1. 多个 Outlook 配置文件

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

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

【讨论】:

    猜你喜欢
    • 2023-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-13
    • 2013-10-08
    • 2017-11-30
    • 2011-05-31
    • 2013-03-10
    相关资源
    最近更新 更多