1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Outlook Vb, Check Address if address BlaBla then send else run script

Discussion in 'Visual Basic ( VB )' started by sauko, Mar 8, 2011.

  1. sauko

    sauko New Member

    Joined:
    Mar 8, 2011
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hi,

    What I want to do is the following. I want the script to search the adress field, if the one you want to send to is @gmail.com, SEDABO (a group with contacts which all use the domain @hotmail.com) or two other internal address group(not global address). IF the script finds one of these it should just go ahead and send the email even though it found C1,C2 or C3 in the subject.

    If the subject is C1,C2 or C3 and the email is supposed to be sent to lets say Robin@Batcave.com it should run the script with the warning.

    This is what I have so far, dont know how to finish it.

    What is done so far:
    +I the warning signs work
    +You can cancel the email if you press no when the warning appears
    + It checks the address for a string, But only one string, and if it finds it, it runs the script instead of just sending the email.
    Code:
      
    Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    Dim strTo As String
    
    strTo = Item.To
    If InStr(1, strTo, "@gmail.com", vbTextCompare) > 0 Then
    
    Dim strSubject As String
    strSubject = Item.Subject
     
    If InStr(1, strSubject, "C1", vbTextCompare) > 0 Then
    Prompt$ = "Are you sure you want to send C1?"
    If MsgBox(Prompt$, vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Check for Subject") = vbNo Then
    Cancel = True
    
    End If
    End If
    
    If InStr(1, strSubject, "C2", vbTextCompare) > 0 Then
    Prompt$ = "Are you sure you want to send C2?"
    If MsgBox(Prompt$, vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Check for Subject") = vbNo Then
    Cancel = True
     
    End If
    End If
     
    If InStr(1, strSubject, "C3", vbTextCompare) > 0 Then
    Prompt$ = "Are you sure you want to send C3"
    If MsgBox(Prompt$, vbYesNo + vbQuestion + vbMsgBoxSetForeground, "Check for Subject") = vbNo Then
    Cancel = True
     
    End If
    End If
    
    End If
    
    End Sub
    
    Thank you for all your help,

    Kind Regards
    Daniel
     

Share This Page