D
deko
I use the following to loop through email messages in the Outlook Inbox:
Dim olmi as Outlook.MailItem
Dim olfi as Outlook.Items
Dim olr As Outlook.Recipient
Dim olrs As Outlook.Recipients
Set olfi = olFolder.Items
For Each olmi In olfi
'match recipient address
Set olrs = olmi.Recipients
For Each olr In olrs 'check every recipient the message was sent to
Debug.Print "checking olr.Address [" & olr.Address & "]"
If olr.Address = strAddress And olmi.SenderEmailAddress <>
olr.Address Then
Debug.Print "Found matching Recipient address!"
End If
End If
Next
Next
The problem is when users have encrypted messages, or messages of SYSTEM
type (e.g. an undeliverable alert from the System Administrator) in their
Inbox. When one of these messages is encountered, a Type Mismatch error is
returned and the code exits the loop. I've tried a On Error Resume Next,
but no luck.
Is there a way to test for encrypted or SYSTEM type messages? It appears
these types of messages are not Outlook.MailItems and therefore the error
occurs as soon as the "For Each olmi In olfi" line is executed. I'm
thinking I could insert a line of code above that For Each statement to test
if the message can or cannot be inspected... ? Other options?
Thanks in advance.
Dim olmi as Outlook.MailItem
Dim olfi as Outlook.Items
Dim olr As Outlook.Recipient
Dim olrs As Outlook.Recipients
Set olfi = olFolder.Items
For Each olmi In olfi
'match recipient address
Set olrs = olmi.Recipients
For Each olr In olrs 'check every recipient the message was sent to
Debug.Print "checking olr.Address [" & olr.Address & "]"
If olr.Address = strAddress And olmi.SenderEmailAddress <>
olr.Address Then
Debug.Print "Found matching Recipient address!"
End If
End If
Next
Next
The problem is when users have encrypted messages, or messages of SYSTEM
type (e.g. an undeliverable alert from the System Administrator) in their
Inbox. When one of these messages is encountered, a Type Mismatch error is
returned and the code exits the loop. I've tried a On Error Resume Next,
but no luck.
Is there a way to test for encrypted or SYSTEM type messages? It appears
these types of messages are not Outlook.MailItems and therefore the error
occurs as soon as the "For Each olmi In olfi" line is executed. I'm
thinking I could insert a line of code above that For Each statement to test
if the message can or cannot be inspected... ? Other options?
Thanks in advance.