' 下面的代码将能够处理来自 Outlook 的几乎所有邮件,' 除了我不知道为什么您正在处理由 Exchange Server 生成的邮件,例如“邮件传递系统”。在这一点上,它看起来确实不是一个“真正的消息”。如果您尝试阅读它,则对象“olItem”“始终为空”。但是,如果您收到此警报“邮件传递系统”并将其转发给自己,然后尝试阅读它,它确实可以正常工作。不要问我为什么,因为我不知道。我只是认为这个“邮件传递系统”'第一次它是一个警报而不是消息,图标也发生了变化,它'不是一个信封图标,而是一个成功与否的传递图标。如果您有任何想法如何处理它,请告知
Set olApp = New Outlook.Application
Set olNamespace = olApp.GetNamespace("MAPI")
Set olInbox = olNamespace.GetDefaultFolder(olFolderInbox).Folders("mFolder")
On Error Resume Next
i = 5
cont1 = 0
Sheet2.Cells(4, 1) = "Sender"
Sheet2.Cells(4, 2) = "Subject"
Sheet2.Cells(4, 3) = "Received"
Sheet2.Cells(4, 4) = "Recepient"
Sheet2.Cells(4, 5) = "Unread?"
Sheet2.Cells(4, 6) = "Link to Report"
For Each olItem In olInbox.Items
myText = olItem.Subject
myTokens = Split(myText, ")", 5)
myText = Mid(myTokens(0), 38, Len(myTokens(0)))
myText = RTrim(myText)
myText = LTrim(myText)
myText = myText & ")"
myLink = ""
myArray = Split(olItem.Body, vbCrLf)
For a = LBound(myArray) To UBound(myArray)
If a = 4 Then
myLink = myArray(a)
myLink = Mid(myLink, 7, Len(myLink))
End If
Next a
Sheet2.Cells(i, 1) = olItem.SenderName
Sheet2.Cells(i, 2) = myText
Sheet2.Cells(i, 3) = Format(olItem.ReceivedTime, "Short Date")
Sheet2.Cells(i, 4) = olItem.ReceivedByName
Sheet2.Cells(i, 5) = olItem.UnRead
Sheet2.Cells(i, 6) = myLink
olItem.UnRead = False
i = i + 1
Next