Reading e-mail without Outlook app open

后端 未结 6 1711
借酒劲吻你
借酒劲吻你 2021-01-12 01:44

Thats what I am using to read e-mail using C#:

outLookApp.NewMailEx += new ApplicationEvents_11_NewMailExEventHandler(outLookApp_NewMailEx);
            Outl         


        
相关标签:
6条回答
  • 2021-01-12 02:06

    This is kind of an old question, but I am going to answer it since I struggled with the same issue for a long time and the previous answers on this page did not really help me.

    I had to write a program and use outlook to send an email on different machines with different UAC-levels and this is what I came up with after a long time.

    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);
    
    0 讨论(0)
  • 2021-01-12 02:08

    Are you sure you want to use Outlook as a proxy?

    people seems to deal low level with such a task in C# (surprising there isn't any built-in component in the framework...)

    Concerning Mat's response, Redemption is indeed a fine product (used it to parse mails upon arrival in outlook), but I doubt it can work without outlook running.

    0 讨论(0)
  • 2021-01-12 02:13

    Use a MAPI client to retrieve the emails and a MIME decoder to read them. Both exists in the lumisoft framework:

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

    0 讨论(0)
  • 2021-01-12 02:14

    You'll likely run into this when Outlook is closed.

    Also following this tutorial will ensure you're doing all the right steps part and parcel.

    Best of luck!

    0 讨论(0)
  • 2021-01-12 02:23

    I would personally not use Outlook as a proxy. If you're trying to ultimately monitor an Exchange store, then I'd use WebDav. Your Exchange server must support it - but if it does, it's a simple XML API. Well, the API bit is simple, but the XML is quite convoluted. But once you've encapsulated this in a bit of code, it's a doddle to use.

    0 讨论(0)
  • 2021-01-12 02:30

    Use the Redemption COM library for your code.

    0 讨论(0)
提交回复
热议问题