Microsoft Office Interop Outlook在本地Visual Studio上工作,而不在iis服务器上工作

时间:2016-12-12 11:24:22

标签: c# asp.net iis outlook

Microsoft.Office.Interop.Outlook.Application oApp = new Microsoft.Office.Interop.Outlook.Application();             Microsoft.Office.Interop.Outlook.MAPIFolder inboxFolder = null;   oApp = new Microsoft.Office.Interop.Outlook.Application();

        Microsoft.Office.Interop.Outlook.NameSpace oNS = oApp.GetNamespace("MAPI");
        var lst = new List<Msg>();
        oNS.Logon("support@**.com", "*****", false, true);
        inboxFolder = oNS.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
        for (int counter = 1; counter <= inboxFolder.Items.Count; counter++)
        {
            dynamic item = inboxFolder.Items[counter];
            item = (Microsoft.Office.Interop.Outlook.MailItem)inboxFolder.Items[counter];
            var msg = new Msg();
            msg.subject = item.Subject;
            msg.senderName = item.SenderName;
            msg.body = item.Body;
            if (item.UnRead == true)
            {
                lst.Add(msg);
            }
        }
        return View(lst.ToList());

0 个答案:

没有答案