应用程序来管理多个Outlook帐户

时间:2015-04-24 12:12:46

标签: c# asp.net email outlook

我有多个Outlook帐户,所有帐户都添加到outlook express。 我可以从一个帐户中列出来自asp.net应用程序的收件箱中的电子邮件,该帐户被设置为默认值。 我可以通过将其设置为默认数据文件来列出来自其他帐户的电子邮件..

这是我的代码:

public static Microsoft.Office.Interop.Outlook.Items GetHotMailInBoxItemsUsingLoggedInOutLookAccount(this string strMailStatus)
    {
        Microsoft.Office.Interop.Outlook.NameSpace _ns;
        Microsoft.Office.Interop.Outlook.MAPIFolder inboxFolder = null;
        Microsoft.Office.Interop.Outlook.Items _items = null;
        Microsoft.Office.Interop.Outlook.Application _application = new Microsoft.Office.Interop.Outlook.Application();
        _ns = _application.Session;
        inboxFolder = _ns.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
        if (strMailStatus.Equals("1"))
        {
            _items = inboxFolder.Items;
        }
        else
        {
            _items = strMailStatus.Equals("2") ? inboxFolder.Items.Restrict("[Unread] = true") : inboxFolder.Items.Restrict("[Unread] = false");
        }
        _items.Sort("ReceivedTime", true);
        return _items;
    }

我想按照自己的意愿切换“_application.Session”。 即:从asp.net应用程序更改默认数据文件..

1 个答案:

答案 0 :(得分:0)

请考虑使用EWS(Exchange Web服务)。有关详细信息,请参阅EWS Managed API, EWS, and web services in Exchange

Microsoft目前不建议也不支持从任何无人参与的非交互式客户端应用程序或组件(包括ASP,ASP.NET,DCOM和NT服务)自动化Microsoft Office应用程序,因为Office在此环境中运行Office时,可能会出现不稳定的行为和/或死锁。

如果要构建在服务器端上下文中运行的解决方案,则应尝试使用已为安全无人值守执行的组件。或者,您应该尝试找到允许至少部分代码在客户端运行的替代方法。如果从服务器端解决方案使用Office应用程序,则应用程序将缺少许多成功运行的必要功能。此外,您将承担整体解决方案稳定性的风险。

Considerations for server-side Automation of Office文章中详细了解相关内容。

相关问题