Access MS Outlook from Windows service

瘦欲@ 提交于 2019-12-24 10:58:46

问题


I try to access MS Outlook from service this way:

oApp = new Outlook.Application();
oNS = (Outlook._NameSpace)oApp.GetNamespace("MAPI");
oNS.Logon(Missing.Value, Missing.Value, false, true);
oFolder = oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);

If run this code as Windows Application it is working properly. But if I try run in as service I get error

Server is not available

at the line

oNS.Logon(Missing.Value, Missing.Value, false, true);

What is the right way to access MS Outlook folder from service?


回答1:


Outlook, just like any other Office app, cannot be used from a service. Your options are

  1. In case of an Exchange mailbox, you can use EWS to connect to a particular mailbox

  2. Extended MAPI (C++ or Delphi only) - you can dynamically create a profile, then add and configure the Exchange MAPI service (MSEMS).

  3. Redemption (any language) - its RDO family of objects can be used in a service. You can use RDOSession.LogonExchangeMailbox / LogonHostedExchangeMailbox / LogonPstStore to make Redemption create a dynamic profile and log to it. You can also use RDOSession.Logon and specify the profile name, but then your service must run as the local user who has that profile instead of the service account.



来源:https://stackoverflow.com/questions/26403680/access-ms-outlook-from-windows-service

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