/ Forums / Advansys Formativ / Creating Solutions with Formativ / If-then-else statement , if mail is send local / Reply To: If-then-else statement , if mail is send local

#6449
Support 2
Moderator

    Please find below an example of disclaimer applet which supports both text and HTML and which checks to see if any outgoing addresses are external. It achieves this by attempting to resolve an address with an embedded ‘@’ sign against the system address book.

    Please let us know if you have any questions.

    Regards,

    Advansys Support

    '-------------------------------------------------------------------------------
    ' Formativ Business Solutions
    ' Disclaimer
    ' Copyright (c) 2002 Advansys Corporation (www.advansyscorp.com)
    ' Version 1.0
    '
    ' This applet appends a disclaimer to the end of the message when the event is
    ' OnSend. If the message recipients are internal GroupWise system users only,
    ' then the applet will not add the disclaimer. The disclaimer can be a plain
    ' text or HTML file (extension must be .htm or .html).
    '
    ' INTEGRATION: This applet requires integration with OnSend event.
    '
    ' Notes: If you are using internet addressing, you will need to set the
    ' DOMAINNAME constant to your company's Internet domain name.
    '-------------------------------------------------------------------------------

    ' DOMAINNAME should be your company's Internet domain name, i.e. advansyscorp.com
    Const DOMAINNAME = "domainname.com" 'do not prefix the domain name with www.
    ' Full path to the location of the HTM file
    FILENAME = Utilities.GetDataDirectory + "Disclaimer.htm"

    '-------------------------------------------------------------------------------
    ' Main line processing
    '-------------------------------------------------------------------------------
    Sub Main(Client, GWEvent)

    Dim Msg
    Dim FSO

    On Error Resume Next
    If ValidMsg(Msg) And (GWEvent = "GW#C#SEND") Then

    Set FSO = CreateObject("Scripting.FileSystemObject")

    If (FSO.FileExists(FILENAME)) Then
    sTo = Msg.To_
    sCC = Msg.CC
    sBC = Msg.BC
    Call GroupWise.FocusSet(9, "")

    If CheckExternalEmail(sTo, sCC, sBC) = FALSE Then
    If FileType And (GroupWise.EnvEditorStyle = 1) Then
    Call GroupWise.SwitchToHTMLView
    End If
    'Set the position where you want to place the disclaimer.
    ' To place the disclaimer at the
    ' top of the message - uncomment the PosTextTop,
    ' end of the message - uncomment PosToEndOfText
    'Call GroupWise.PosTextTop
    Call GroupWise.PosToEndOfText
    Call GroupWise.Retrieve(FILENAME)
    End If

    End If

    Set FSO = Nothing

    End If

    End Sub

    '-------------------------------------------------------------------------------
    ' Decide whether the file is HTM/HTML or text file?
    '-------------------------------------------------------------------------------
    Function FileType

    Dim sFileType

    If (Instr(1, FILENAME, ".") <> 0) then
    sFileType = Split(FILENAME, ".", -1, 1)
    sType = sFileType(UBound(sFileType))
    If (UCase(sType) = "HTM") Or (UCase(sType) = "HTML") Then
    FileType = TRUE
    End If
    End If

    End Function

    '-------------------------------------------------------------------------------
    ' Check any external email addresses which exist in the recipient list
    '-------------------------------------------------------------------------------
    Function CheckExternalEmail(sTo, sCC, sBC)

    'To field
    If Len(sTo) > 0 then
    If ResolveAddress(sTo) = FALSE Then
    CheckExternalEmail = FALSE
    Exit Function
    Else
    CheckExternalEmail = TRUE
    End If
    End If

    'CC Field
    If Len(sCC) > 0 Then
    If ResolveAddress(sCC) = FALSE Then
    CheckExternalEmail = FALSE
    Exit Function
    Else
    CheckExternalEmail = TRUE
    End If
    End If

    'BCC Field
    If Len(sBC) > 0 Then
    If ResolveAddress(sBC) = FALSE Then
    CheckExternalEmail = FALSE
    Exit Function
    Else
    CheckExternalEmail = TRUE
    End If
    End If


    End Function


    '-------------------------------------------------------------------------------
    ' Resolve Address
    '-------------------------------------------------------------------------------
    Function ResolveAddress(ByVal Recp)

    Dim sMail
    Dim sEntry
    Dim sAddress
    Dim sReturnAddr

    sAddress = Trim(Recp)

    'If the recipient list contains more than one entry and separated by ';' then proceed
    If (Instr(1, sAddress, ";") <> 0) Then
    sEntry = Split(sAddress, ";", -1, 1)
    For x = 0 to UBound(sEntry)
    sMail = Trim(sEntry(x))
    If MailCheck(sMail) Then
    ResolveAddress = TRUE
    Else
    ResolveAddress = FALSE
    Exit Function
    End If
    Next
    Else
    If MailCheck(sAddress) Then
    ResolveAddress = TRUE
    Else
    ResolveAddress = FALSE
    End If
    End If

    End Function

    '-------------------------------------------------------------------------------
    ' Check for the external mail
    '-------------------------------------------------------------------------------
    Function MailCheck(sMail)

    Dim sEmail

    If (Instr(1, sMail, "@") = 0) Then
    On Error Resume Next
    sEmail = GroupWise.AddressBookResolveFullName(sMail)

    If (Instr(1, sEmail, "@") <> 0) Then
    If (Instr(1, sEmail, DOMAINNAME) = 0) Then
    MailCheck = FALSE
    Else
    MailCheck = TRUE
    End If
    Else
    MailCheck = TRUE
    End If
    Else
    If (Instr(1, sMail, DOMAINNAME) = 0) Then
    MailCheck = FALSE
    Else
    MailCheck = TRUE
    End If
    End If

    End Function

    '-------------------------------------------------------------------------------
    ' Do we have a composing item available?
    '-------------------------------------------------------------------------------
    Function ValidMsg(ByRef Msg)

    On Error Resume Next
    Set Msg = GroupWise.ComposingItem

    If Msg is Nothing then
    ValidMsg = FALSE
    Else
    ValidMsg = TRUE
    End If

    End Function