PDA

View Full Version : If a specific address in the address field then send otherwise run script.



Sakke
03-10-2011, 03:49 AM
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 'Here I want to check for @gmail and or SEBABA(Group) and or @hotmail.com.

'Here it should just send the mail if it finds one or more of @gmail.com SEBABA in the address field.

'Else If it does not find SEBABA, @gmail.com and so on then it should run the following script which already works fine :)


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
Sakke

Sakke
03-10-2011, 04:20 AM
Of course I want the script to check all this when one presses the SEND button :)