【问题标题】:how to allow permanent access to outlook through C#如何允许通过 C# 永久访问 Outlook
【发布时间】:2011-09-16 17:33:52
【问题描述】:

我已尝试访问和阅读 Outlook 邮件。我尝试了以下代码,但它给了我一个安全警告弹出窗口,说“程序正在尝试访问存储在 Outlook Express 中的电子邮件地址信息。”当我尝试在 foreach 中访问 Microsoft.Office.Interop.Outlook.MailItem 时。

    const string OUTLOOK_PROCESSNAME = "OUTLOOK";
    const string OUTLOOK_APPLICATIONNAME = "Outlook.Application";

    private static Microsoft.Office.Interop.Outlook.Application StartOutlookApplication()
    {
        return StartApplication(OUTLOOK_PROCESSNAME, OUTLOOK_APPLICATIONNAME) as Microsoft.Office.Interop.Outlook.Application;
    }

    private static object StartApplication(string processName, string applicationName)
    {
        // Application object
        object app = null;
        try
        {

            // is there an existing application object ?
            if (Process.GetProcessesByName(processName).Length > 0)
            {

                // use the GetActiveObject method to attach an existing application object
                app = Marshal.GetActiveObject(applicationName);
            }
            if (app == null)
            {
                // create a new instance
                Type t = Type.GetTypeFromProgID(applicationName);
                app = Activator.CreateInstance(t);
            }


        }
        catch (System.Exception ex)
        {
            // Some Logging
            Trace.WriteLine(string.Format("Error while starting the Application: {0}", applicationName));
        }
        return app;

    }


Microsoft.Office.Interop.Outlook.MAPIFolder subFolder = null;
            Microsoft.Office.Interop.Outlook.Application app = StartOutlookApplication();
            Microsoft.Office.Interop.Outlook.NameSpace NS = app.GetNamespace("MAPI");
            Microsoft.Office.Interop.Outlook.MAPIFolder inboxFld = NS.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
            lastupdateddate = getmostrecentupdatetime();
            DateTime lastupdated=Convert.ToDateTime(lastupdateddate);
            subFolder = inboxFld.Folders[Inboxpath];

            foreach (Microsoft.Office.Interop.Outlook.MailItem t in subFolder.Items)
            {
                if (t.SenderEmailAddress.Contains(senderemail))
                {

请有人帮助我。我需要在不显示此警告消息的情况下运行我的程序。

【问题讨论】:

    标签: c# wpf outlook


    【解决方案1】:

    兑换库将绕过其中的大部分。 http://www.dimastr.com/redemption/

    【讨论】:

      猜你喜欢
      • 2013-10-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-21
      • 1970-01-01
      • 2014-11-20
      • 2019-07-21
      • 1970-01-01
      相关资源
      最近更新 更多