我正在尝试创建一个程序,该程序从 Outlook(2007 桌面版)收件箱中检索所有电子邮件并将它们放入 DataGridView。
代码:
Imports Outlook = Microsoft.Office.Interop.Outlook
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim dt As DataTable
Try
Dim app As Outlook.Application = New Outlook.Application()
Dim ns As Outlook.[NameSpace] = app.GetNamespace("MAPI")
Dim inbox As Outlook.MAPIFolder = ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox)
ns.SendAndReceive(True)
dt = New DataTable("Inbox")
dt.Columns.Add("Subject", GetType(String))
dt.Columns.Add("Sender", GetType(String))
dt.Columns.Add("Body", GetType(String))
dt.Columns.Add("Date", GetType(String))
DataGridView1.DataSource = dt
For Each item As Object In inbox.Items
If TypeOf item Is Outlook.MailItem Then
Dim item1 As Outlook.MailItem = CType(item, Outlook.MailItem)
dt.Rows.Add(New Object() {item1.Subject, item1.Sender, item1.HTMLBody, item1.SentOn.ToLongDateString() & "" + item1.SentOn.ToLongTimeString()})
End If
Next
MessageBox.Show("done")
Catch ex As Exception
MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.[Error])
End Try
End Sub
End Class
当我尝试构建项目时,出现以下错误:
System.Runtime.InteropServices.COMException (0x80040154):检索具有 CLSID {0006F03A-0000-0000-C000-000000000046} 的组件的 COM 类工厂失败,原因是以下错误:80040154 未注册类(HRESULT 异常:0x80040154(REGDB_E_CLASSNOTREG) ))
更新
我已将编译器 CPU 更改为 x86 和 x64,这并不能解决错误。