scan emails in the folder for certain phrase

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I hope I am not repeating the questions but I looked and could not find it.
I don't know if this is possible but this is what I would like to do.
I receive emails everyday stating if the report ran successfully. If ran
successfully the email will simply say " successful", if not, then the email
will contain the word " reject" and has the username that was rejected.

I would like to:
Look for the latest email (most recent email) in the folder named " Report
Status",
Search for the phrase " rejected" in the body of the email.

I would like to run this in Acess database form. Have command button to
search the email and if there is a rejection I would like msgbox to be the
body of the email.
If no reject email, then msgbox willl simply say " No rejects".

Can anyone help me with this?

Thank you
 
This code will take you most of the way, you just have to pass a valid
MAPIFolder reference to the procedure and desing a custom message box form
that will be big enough to display the message body text:

Sub SearchForRejectedReports(SourceFolder As Outlook.MAPIFolder)
'The SourceFolder argument requires that a reference to the folder that is
to be searched
'be passed to this procedure
'Use either NameSpace.GetDefaultFolder, or walk the Folders collection of
any folder to get the desired
'MAPIFolder object reference

Dim objItems As Outlook.Items, objMsg As Outlook.MailItem
Dim intX As Integer

Set objItems = SourceFolder.Items
objItems.Sort "Received", True
For intX = 1 To objItems.Count
If objItems.Item(intX).Class = olMail Then
'Found the most recent e-mail message
Set objMsg = objItems.Item(intX)
If InStr(1, objMsg.Body, "rejected", vbTextCompare) > 0 Then
'This message contains the word "rejected"
'You'll need to design a custom form to mimic a message box
that would be
'big enough to contain the text of the message body which is
available here
'by calling the value of objMsg.Body
GoTo Leave:
End If
End If
Next

Leave:
Set objItems = Nothing
Set objMsg = Nothing
End Sub
 
Back
Top