H
Hotnumbers2000
Hellow everyone, I am new to the forum, so I apologize for asking a silly
question. I need to modifiy a code that will look in the body of an e-mail
if the ciritera is meet then send out the alert msg.
I have it currently looking into the Subject. This part works great. Then
I need to look into the body and if it has the following "1 - High Impact;
Extreme Financial Impact"
Below is the code.
' This routine is called whenever new mail arrives
Private Sub Application_NewMail()
Dim myFolder As MAPIFolder
' Reference Outlook's Inbox folder
Set myFolder =
ThisOutlookSession.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)
' Iterate through each email in the inbox
For Each Email In myFolder.Items
' Is this email still marked as unread?
If Email.UnRead = True Then
' This email is marked as unread, so let's process it
' Get the sender's email address from the message
SenderEmail = ReplyToAddress(Email)
' Is this email from a known person on my list and not spam?
RecipientName = KnownSender(SenderEmail)
' If not a known person, is it a known subject? The "LCase" lets
the
' script identify keywords in the subject regardless of case.
If RecipientName = "" Then
RecipientName = KnownText(LCase(Email.Subject))
End If
If RecipientName <> "" Then
' Obtain the first 20 characters of the email's subject line
SubjectText = Left(Email.Subject, 20)
' Obtain the first 120 characters of the email's body
BodyText = Left(Email.Body, 130)
' Build a display line containing the name, email subject,
and body
'Maybe'' SenderName = ">" + RecipientName + Mid(Space(12), 1,
12 - Len(RecipientName))
' Prepare to send out an SMS text message to a cellphone or
a msg to regular email
Set OutgoingEmail = Application.CreateItem(olMailItem)
' --> Replace the following email address with your own
SMS/email address <--
Set OutgoingRecipient =
OutgoingEmail.Recipients.Add("(e-mail address removed)")
With OutgoingEmail
.Subject = SenderName + " " + SubjectText
.Body = BodyText
.Send
End With
' Mark the just-processed email as read so we will not send
a notification again
Email.UnRead = False
End If
End If
Next
Set OutgoingEmail = Nothing
Set OutgoingRecipient = Nothing
Set myFolder = Nothing
End Sub
' This routine determines if the email is from someone on your 'known list'
' and contains 3 example recipients that you must change
Function KnownSender(EmailAddress)
' --> Repeat this section and modify the email address and 'KnownSender'
' value for each person that you want on your notification list
If StrComp(EmailAddress, "(e-mail address removed)", vbTextCompare)
= 0 Then
KnownSender = "Studio Mail Service"
' <--(End of section) Next line must be an 'ElseIf' or "End If' if the
last entry
''' ElseIf StrComp(EmailAddress, "(e-mail address removed)",
vbTextCompare) = 0 Then
''' KnownSender = "Studio Mail Service"
' Example for a message from "(e-mail address removed)" who you want
identified
' as "Agatha"
''' ElseIf StrComp(EmailAddress, "Studio.Mail.Servicexxx.com",
vbTextCompare) = 0 Then
''' KnownSender = "Studio Mail Service"
End If
End Function
' Find out who this email is from - located in either the 'address' or
'name' fields
Function ReplyToAddress(Email)
Set objReply = Email.Reply
On Error Resume Next
Set objRecipient = objReply.Recipients.Item(1)
ReplyToAddress = objRecipient.Address
If ReplyToAddress = "" Then
ReplyToAddress = objRecipient.Name
End If
Set objRecipient = Nothing
Set objReply = Nothing
End Function
' Here you enter keywords you want to be alerted to if they appear in the
subject
' line. Your keywords must be listed here in lowercase for the script to
identify them
' in the subject, as the script converts the entire subject line to lowercase.
Function KnownText(Text)
If InStr(Text, "sap help issue application") Then
KnownText = "sap help issue application"
''' ElseIf InStr(Text, "sap help issue application") Then
''' KnownText = "sap help issue application"
End If
End Function
question. I need to modifiy a code that will look in the body of an e-mail
if the ciritera is meet then send out the alert msg.
I have it currently looking into the Subject. This part works great. Then
I need to look into the body and if it has the following "1 - High Impact;
Extreme Financial Impact"
Below is the code.
' This routine is called whenever new mail arrives
Private Sub Application_NewMail()
Dim myFolder As MAPIFolder
' Reference Outlook's Inbox folder
Set myFolder =
ThisOutlookSession.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)
' Iterate through each email in the inbox
For Each Email In myFolder.Items
' Is this email still marked as unread?
If Email.UnRead = True Then
' This email is marked as unread, so let's process it
' Get the sender's email address from the message
SenderEmail = ReplyToAddress(Email)
' Is this email from a known person on my list and not spam?
RecipientName = KnownSender(SenderEmail)
' If not a known person, is it a known subject? The "LCase" lets
the
' script identify keywords in the subject regardless of case.
If RecipientName = "" Then
RecipientName = KnownText(LCase(Email.Subject))
End If
If RecipientName <> "" Then
' Obtain the first 20 characters of the email's subject line
SubjectText = Left(Email.Subject, 20)
' Obtain the first 120 characters of the email's body
BodyText = Left(Email.Body, 130)
' Build a display line containing the name, email subject,
and body
'Maybe'' SenderName = ">" + RecipientName + Mid(Space(12), 1,
12 - Len(RecipientName))
' Prepare to send out an SMS text message to a cellphone or
a msg to regular email
Set OutgoingEmail = Application.CreateItem(olMailItem)
' --> Replace the following email address with your own
SMS/email address <--
Set OutgoingRecipient =
OutgoingEmail.Recipients.Add("(e-mail address removed)")
With OutgoingEmail
.Subject = SenderName + " " + SubjectText
.Body = BodyText
.Send
End With
' Mark the just-processed email as read so we will not send
a notification again
Email.UnRead = False
End If
End If
Next
Set OutgoingEmail = Nothing
Set OutgoingRecipient = Nothing
Set myFolder = Nothing
End Sub
' This routine determines if the email is from someone on your 'known list'
' and contains 3 example recipients that you must change
Function KnownSender(EmailAddress)
' --> Repeat this section and modify the email address and 'KnownSender'
' value for each person that you want on your notification list
If StrComp(EmailAddress, "(e-mail address removed)", vbTextCompare)
= 0 Then
KnownSender = "Studio Mail Service"
' <--(End of section) Next line must be an 'ElseIf' or "End If' if the
last entry
''' ElseIf StrComp(EmailAddress, "(e-mail address removed)",
vbTextCompare) = 0 Then
''' KnownSender = "Studio Mail Service"
' Example for a message from "(e-mail address removed)" who you want
identified
' as "Agatha"
''' ElseIf StrComp(EmailAddress, "Studio.Mail.Servicexxx.com",
vbTextCompare) = 0 Then
''' KnownSender = "Studio Mail Service"
End If
End Function
' Find out who this email is from - located in either the 'address' or
'name' fields
Function ReplyToAddress(Email)
Set objReply = Email.Reply
On Error Resume Next
Set objRecipient = objReply.Recipients.Item(1)
ReplyToAddress = objRecipient.Address
If ReplyToAddress = "" Then
ReplyToAddress = objRecipient.Name
End If
Set objRecipient = Nothing
Set objReply = Nothing
End Function
' Here you enter keywords you want to be alerted to if they appear in the
subject
' line. Your keywords must be listed here in lowercase for the script to
identify them
' in the subject, as the script converts the entire subject line to lowercase.
Function KnownText(Text)
If InStr(Text, "sap help issue application") Then
KnownText = "sap help issue application"
''' ElseIf InStr(Text, "sap help issue application") Then
''' KnownText = "sap help issue application"
End If
End Function