我正在开发一个大约有15个用户的应用程序。每个用户都必须能够以编程方式单击按钮并阅读其共享功能邮箱中的电子邮件(称为媒体处理)。
当我在本地测试我的代码时,一切正常。但是现在我把它发布到服务器上了,它已经不能用了(因为它可能在服务器上的邮箱而不是用户的邮箱中查找。
在我的web.config中:
<add key="asFuncMailboxInbox" value="Media Processing" />
<add key="asFuncMailboxOutbox" value="902. Outbox" />
这是我处理电子邮件的方法:
string inboxName = WebConfigurationManager.AppSettings["asFuncMailboxInbox"];
string outboxName = WebConfigurationManager.AppSettings["asFuncMailboxOutbox"];
try
{
OutlookApp myApp = new OutlookApp();
OutlookNameSpace mapiNameSpace = myApp.GetNamespace("MAPI");
MapiFolder myInbox = mapiNameSpace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
MapiFolder mySubFolder = myInbox.Folders[inboxName];
MapiFolder destinationFolder = myInbox.Folders[outboxName];
var myItems = mySubFolder.Items;
myItems.Sort("[ReceivedTime]", true);
count = 0;
if (myItems.Count > 0)
{
totalCount = myItems.Count;
for (var i = myItems.Count; i > 0; i--)
{
var itemObject = myItems[i] as MailItem;
if (itemObject != null)
{
var isOk = NewBankFactoryHelper.IsMessageCorrectlyConstructed(itemObject.Body);
if (isOk)
{
StoreNewBankRequestEmailData(itemObject);
itemObject.Move(destinationFolder);
count++;
}
}
}
}
}
catch (System.Exception e)
{
hasError = true;
errorMessage = e.ToString();
}
finally
{
template = string.Format(CommonResources.Label_RequestsDownloadSuccess, count, totalCount);
if (count < totalCount)
{
template += CommonResources.Label_EmailIncorrectFormat;
}
if (hasError)
{
template += string.Format(CommonResources.Label_RequestDownloadFailed, errorMessage);
}
}
答案 0 :(得分:0)
Microsoft目前不建议也不支持从任何无人参与的非交互式客户端应用程序或组件(包括ASP,ASP.NET,DCOM和NT服务)自动化Microsoft Office应用程序,因为Office在此环境中运行Office时,可能会出现不稳定的行为和/或死锁。
如果要构建在服务器端上下文中运行的解决方案,则应尝试使用已为安全无人值守执行的组件。或者,您应该尝试找到允许至少部分代码在客户端运行的替代方法。如果从服务器端解决方案使用Office应用程序,则应用程序将缺少许多成功运行的必要功能。此外,您将承担整体解决方案稳定性的风险。请在Considerations for server-side Automation of Office文章中详细了解相关内容。
如果您只处理Exchange邮箱,可以考虑使用EWS,有关详细信息,请参阅EWS Managed API, EWS, and web services in Exchange。您也可以考虑使用任何不需要在计算机上安装Outlook的第三方组件。或者只使用低级API - 扩展MAPI。