阅读未打开Outlook应用程序的电子邮件

多数民众赞成我使用C#阅读电子邮件:

outLookApp.NewMailEx += new ApplicationEvents_11_NewMailExEventHandler(outLookApp_NewMailEx); Outlook.NameSpace olNameSpace = outLookApp.GetNamespace("mapi"); olNameSpace.Logon("xxxx", "xxxxx", false, true); Outlook.MAPIFolder oInbox = olNameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox); Outlook.Items oItems = oInbox.Items; MessageBox.Show("Total : " + oItems.Count); //Total Itemin inbox oItems = oItems.Restrict("[Unread] = true"); MessageBox.Show("Total Unread : " + oItems.Count); //Unread Items Outlook.MailItem oMsg; Outlook.Attachment mailAttachement; for (int i = 0; i < oItems.Count; i++) { oMsg = (Outlook.MailItem)oItems.GetFirst(); MessageBox.Show(i.ToString()); MessageBox.Show(oMsg.SenderName); MessageBox.Show(oMsg.Subject); MessageBox.Show(oMsg.ReceivedTime.ToString()); MessageBox.Show(oMsg.Body); 

我面临的问题是此应用程序仅在Outlook在计算机上打开时才有效。 如果Outlook已关闭,则会抛出exception:

服务器不可用。 如果此情况仍然存在,请与管理员联系。

无论如何我可以阅读Outlook打开的电子邮件吗?

当Outlook关闭时,您可能会遇到此问题 。

此后, 本教程还将确保您正在执行所有正确的步骤part and parcel。

祝你好运!

这是一个古老的问题,但我会回答这个问题,因为我长期以来一直在努力解决同样的问题,而此页面上的回答并没有真正帮助我。

我不得不编写一个程序并使用outlook在不同的UAC级别的机器上发送电子邮件,这是我在很长一段时间后想出来的。

 using Outlook = Microsoft.Office.Interop.Outlook; // Create the Outlook application. Outlook.Application oApp = null; // Check whether there is an Outlook process running. int outlookRunning = Process.GetProcessesByName("OUTLOOK").Length; if (outlookRunning > 0) { // If so, use the GetActiveObject method to obtain the process and cast it to an Application object. try { oApp = Marshal.GetActiveObject("Outlook.Application") as Outlook.Application; } catch (Exception) { oApp = Activator.CreateInstance(Type.GetTypeFromProgID("Outlook.Application")) as Outlook.Application; } finally { // At this point we must kill Outlook (since outlook was started by user on a higher prio level than this current application) // kill Outlook (otherwise it will only work if UAC is disabled) // this is really a kind of last resort Process[] workers = Process.GetProcessesByName("OUTLOOk"); foreach (Process worker in workers) { worker.Kill(); worker.WaitForExit(); worker.Dispose(); } } } else { // If not, create a new instance of Outlook and log on to the default profile. oApp = new Outlook.Application(); Outlook.NameSpace nameSpace = oApp.GetNamespace("MAPI"); try { // use default profile and DO NOT pop up a window // on some pc bill gates fails to login without the popup, then we must pop up and lets use choose profile and allow access nameSpace.Logon("", "", false, Missing.Value); } catch (Exception) { // use default profile and DO pop up a window nameSpace.Logon("", "", true, true); } nameSpace = null; } // Done, now you can do what ever you want with the oApp, like creating a message and send it // Create a new mail item. Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem); 

您确定要将Outlook用作代理吗?

人们 似乎在C#中处理这样一个任务的低级别(令人惊讶的是框架中没有任何内置组件……)

关于Mat的回应,Redemption确实是一个很好的产品(用于在到达前景时解析邮件),但我怀疑它可以在没有前景运行的情况下工作。

我个人不会使用Outlook作为代理。 如果您正在尝试最终监控Exchange存储,那么我将使用WebDav。 您的Exchange服务器必须支持它 – 但如果确实如此,则它是一个简单的XML API。 那么,API位很简单,但XML非常复杂。 但是一旦你将它封装在一些代码中,它就是一个轻而易举的使用方法。

使用MAPI客户端检索电子邮件和MIME解码器以读取它们。 两者都存在于lumisoft框架中:

http://www.lumisoft.ee/lswww/download/downloads/Net/

使用Redemption COM库代码。