Results 1 to 22 of 22

Thread: Promt Warning List External Users, on VB Script to checks for external users

Threaded View

  1. #7
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    5,261

    Re: Promt Warning List External Users, on VB Script to checks for external users

    Quote Originally Posted by charli1 View Post
    That was the suggested sollution by westconn1,

    Following the full code.
    Probably i missed something, could you please update it in case i missed any variable here?

    vb Code:
    1. Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    2.     Dim objMail As Outlook.MailItem
    3.     Dim objRecipients As Outlook.Recipients
    4.     Dim i As Long
    5.     Dim strRecipientAddress As String
    6.     Dim strPrompt As String
    7.  
    8.     If TypeOf Item Is MailItem Then
    9.        Set objMail = Item
    10.        Set objRecipients = objMail.Recipients
    11.  
    12.        For i = 1 To objRecipients.Count     ' no need to step backwards as you are not removing items from the collection
    13.             strRecipientAddress = objRecipients.Item(i).Address
    14.             domain = Mid(strRecipientAddress, InStr(s, "@"))
    15.            
    16.         Select Case domain
    17.             Case "@my1domain.com", "@my2domain.com", "@my3domain.com", "@my4domain.com", "@my5domain.com"
    18.             Case Else:     rejects = rejects & vbNewLine & strRecipientAddress
    19.         End Select
    20.       Next
    21.          
    22.          If rejects <> "" Then
    23.           strPrompt = "This email will be sent outside of the company to:" & vbNewLine & strRecipientAddress & vbNewLine & "Please check recipient address." & vbNewLine & vbNewLine & "Do you still wish to send?"
    24.             If MsgBox(strPrompt, vbYesNo + vbExclamation + vbMsgBoxSetForeground, "Check Address") = vbNo Then
    25.             Cancel = True
    26.          End If
    27.         End If
    28.     End If
    29. End Sub
    Your Problem is in Line 14 the InStr(s, "@")
    you don't assign a value to "s"
    at a guess: that "s" should be strRecipientAddress
    Last edited by Zvoni; Sep 24th, 2018 at 03:54 AM.
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width