Undelivered emails

#1
Hi, I am trying to get any emails that come back undelivered. I had been using Get Received Items (Basic) from the MS Outlook Email VBO. It will pick up any emails in the inbox and put them in a collection but it will ignore any emails that came back Undelivered. Does anybody know how I can get these undelivered emails? Thanks
 
#2
Hi, I am trying to get any emails that come back undelivered. I had been using Get Received Items (Basic) from the MS Outlook Email VBO. It will pick up any emails in the inbox and put them in a collection but it will ignore any emails that came back Undelivered. Does anybody know how I can get these undelivered emails? Thanks



I have the same issue. Anyone solved it?

Thanks
Javier.
 
#3
Hi all!

I had a similar problem and I've found that undelivered e-mails are of a different object than regular e-mail. In code stage of action "Internal_Get Items" you can find this line:
Code:
If Not TypeOf item Is MailItem Then Continue For
.

Regular e-mails are MailItem objects but undeliverable e-mails are ReportItem objects. So you have to change this line of code. And since ReportItem has different properties, you will not find SenderName etc. and you will have to change these lines too (and output collection of course).

You can find ReportItem properties here https://docs.microsoft.com/en-us/office/vba/api/outlook.reportitem

I duplicated the original action and created new for all the other types of e-mail (I believe there are only two types, but I can be wrong here). Here is my code:

Code:
.
.
.

Dim dataTable As New Data.DataTable
dataTable.Columns.Add("EntryID", Type.GetType("System.String"))
dataTable.Columns.Add("Subject", Type.GetType("System.String"))
dataTable.Columns.Add("Body", Type.GetType("System.String"))
dataTable.Columns.Add("CreationTime", Type.GetType("System.DateTime"))
dataTable.Columns.Add("Unread", Type.GetType("System.Boolean"))

Dim folderItems = If(Filter_Expression <> "", folder.Items.Restrict(Filter_Expression), folder.Items)

For Each item As Object In folderItems
    If TypeOf item Is MailItem Then Continue For
    Dim row As Data.DataRow = dataTable.NewRow
    row("EntryID") = item.EntryID
    row("Subject") = item.Subject
    row("Body") = item.Body
    row("CreationTime") = item.CreationTime
    row("Unread") = item.Unread
    dataTable.Rows.Add(row)
    Item_Count += 1
Next
Items = dataTable
 
Top