0

我正在尝试将 MS Outlook 集成到 asp.net 中。我的代码(如下)捕获越界错误。我究竟做错了什么?我没有正确收到收件箱消息吗?提前致谢

编辑:基于我的调试
inbox = name.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox) 不返回任何内容。我不知道为什么

 Dim ol As Outlook.Application = New Outlook.Application
        Dim name As Microsoft.Office.Interop.Outlook._NameSpace
        Dim inbox As Microsoft.Office.Interop.Outlook.MAPIFolder
        Dim item As Microsoft.Office.Interop.Outlook.PostItem
        Dim subF As Microsoft.Office.Interop.Outlook.MAPIFolder

        Try
            name = ol.GetNamespace("MAPI")
            name.Logon(Nothing, Nothing, False, False)
            inbox = name.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox)
            subF = inbox.Folders(0)
            Dim ctr As Integer
            For ctr = 0 To subF.Items.Count
                item = subF.Items(ctr)
                Label1.Text += "Subject: " + item.Subject + "<br/>"
                Label1.Text += "Date: " + item.SentOn.ToLongDateString() + " " + item.SentOn.ToLongTimeString() + "<br/>"
                Label1.Text += "Category: " + item.Categories + "<br/>"
                Label1.Text += "Body: " + item.Body + "<br/>"
                Label1.Text += "HtmlBody: " + item.HTMLBody + "<br/>"


            Next



        Catch ex As System.Runtime.InteropServices.COMException

        End Try
4

2 回答 2

1

首先,Outlook 中的所有集合都是基于 1 的,而不是 0。

其次,Outlook 与任何其他 Office 应用程序一样,不能在 IIS 等服务中使用。如果您需要代码在服务中运行,CDO 1.21(不再由 Outlook 安装)或Redemption是您的选择。但请记住,代码将访问服务器上的 Outlook 数据,而不是客户端,这可能不是您想要的。

于 2013-11-05T02:12:50.367 回答
0

检查您的索引库

改变

For ctr = 0 To subF.Items.Count

For ctr = 1 To subF.Items.Count

或者可能

For ctr = 0 To subF.Items.Count - 1

...如果微软最终摆脱了 Outlook 对象的 base-1-indexing 方案。


确保确实有一个文件夹!

检查以确保收件箱包含子文件夹。如果没有,请使用收件箱本身。

inbox = name.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox)
If inbox.Folders.Count > 0 Then
    subf = inbox.Folders(1)
Else
    subf = inbox
End If
于 2013-11-05T02:00:48.517 回答