简体   繁体   中英

Change email subject depending on body text

We get email alerts from the system of one of our vendors with subjects "Alert for [SITENAME] - Uplink status changed" and where the email body will contain one of following two texts strings:

"the security appliance switched to using Internet 2 as its uplink."
or
"the security appliance switched to using Internet 1 as its uplink."

We need to read each email to see if an uplink has gone up or down and I want this to be visible from the subject.

Sub changesubject()
    
    Dim myMessage As Outlook.MailItem 
    Set myMessage = Outlook.ActiveInspector.CurrentItem 
    
    If myMessage.Body = "Internet 2 as its uplink" then
        myMessage.Subject = myMessage.Subject & "- PRIMARY LINK DOWN"
    End If
    
    If myMessage.Body = "Internet 1 as its uplink" then
        myMessage.Subject = myMessage.Subject & "- PRIMARY LINK UP"
    End If

End Sub

Use Like in your If statements instead of = . This explains how the Like operator works. You can also Google "VBA Like" and you will get more results

Sub changesubject()

Dim myMessage As Outlook.MailItem 
Set myMessage = Outlook.ActiveInspector.CurrentItem 

If myMessage.Body Like "*Internet 2 as its uplink*" then
    myMessage.Subject = myMessage.Subject & "- PRIMARY LINK DOWN"
End If

If myMessage.Body Like "*Internet 1 as its uplink*" then
    myMessage.Subject = myMessage.Subject & "- PRIMARY LINK UP"
End If

End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM