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

  • Creator
    Topic
  • #3870
    Gem.Rhenen
    Participant

      We would like to add a Disclamer to mail send externaly. Obviously we don’t want the disclaimer added to mail send insternaly. How do we determine if a mail is send External?

      So far we created this:



      ‘ Add Disclaimer



      const OpenFileForReading = 1
      Const cExit = 0
      Dim NewLine

      Sub Main(Client, GWEvent)

      Dim SigFile
      Dim Msg
      Dim myVar
      Dim ListBox

      NewLine = Chr(10)

      if (…..) then

      Set Msg = GroupWise.ComposingItem
      if GWEvent = “GW#C#REPLY” then
      Msg.BodyText = NewLine & GetSignatureText(SigFile) & NewLine & NewLine & Msg.BodyText
      else
      Msg.BodyText = Msg.BodyText & NewLine & NewLine & GetSignatureText(SigFile)
      end if
      Set Msg = nothing

      end if

      End Sub



      ‘ Read DISCLAIMER as text.


      Function GetSignatureText(SigFile)

      Dim FSO
      Dim TextStream
      Const Disclaimer = “l:emaildisclaimer.txt”

      Set FSO = CreateObject(“Scripting.FileSystemObject”)
      Set TextStream = FSO.OpenTextFile(Disclaimer, OpenFileForReading)
      GetSignatureText = TextStream.ReadAll
      TextStream.Close
      Set FSO = nothing

      End Function

      Thanks in addvance

    • Author
      Replies
    • #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
        #6447
        Gem.Rhenen
        Participant

          The script is working perfectly, but sometimes, with some specific users, we get the DISCLAIMER in the middle of the text.
          In spite of the fact that we use the line “Call GroupWise.PosToEndOfText”.

          How can we force the DISCLAIMER to be definitely at the bottom of our email?

          #6452
          Support 1a
          Participant

            I’m not sure why this would happen. It could be a timing issue related to the focus. Try inserting a FocusSet() command (i.e set the focus to the body text) immediately before the “Call GroupWise.PosToEndOfText” line.

            Advansys Support

            #6454
            Anonymous

              Advansys Support Group,

              I had been working on this Disclaimer for a few days, it was working great until last friday all of a sudden the appelet started to error on me. I have been using a “html” file for disclaimer. The error is stated as: “The file could not be interpreted as a standard internet message mail”. What does this mean? What do I need to do? I did try to re-create the applet but in vain. Please advise me about the same ASAP. Waiting for your reply.

              Thanks for your help.
              Regards,
              KD
              dkothandaraman@analysts.com

              #6455
              Support 1
              Participant

                GroupWise displays this error for an HTML-formatted message when inserting HTML that is corrupt (or non-standard). The problem here could also be related to the version of GroupWise.

                Please send a copy of the HTML disclaimer file, the applet and your Formativ configuration information to the email address below:

                Support@advansyscorp.com

                (You can access Formativ configuration via the main GroupWise menu: select Help | About Formativ. When the about box appears, select the configuration tab, then press the ‘copy to clipboard’ button. Then paste the contents of the clipboard into the body of your email message.)

                Advansys Support

                #6446
                Anonymous

                  I have already sent the files you had asked. Please let me know whats causing the problem. I’m waiting for your reply before going any forward about the same.

                  #6445
                  Support 1
                  Participant

                    Thank you for sending the files. I have forwarded them to our engineers.

                    We will be in touch as soon as we have a resolution for you.

                    Advansys Support

                    #6453
                    Anonymous

                      Having some problems with this code as written.

                      sEmail=Groupwise.AddressBookResolveFullName (sMail)
                      always returns nothing.

                      If we insert the On Error Resume Next then the code continues, always inserting the disclaimer because MailCheck comes back false.

                      This indicates to me that the Resolution is always throwing an error. It appears when typing the message that the Display Name comes up (resolves), but sending this Display Name to the Groupwise.AddressBookResolveFullName code causes it to fail.

                      Anything obvious? Does it work on your end. Using GW 6.0.2 and Formativ 1.6. Thanks for whatever you can do.

                      #6450
                      Support 1
                      Participant

                        Your code uses incorrect syntax for the token AddressBookResolveFullName. A user ID is required as well the full name; use an empty string for the current (logged-in) user. Try the following code:

                          MsgBox GroupWise.AddressBookResolveFullName("Tendulkar", "")

                        I hope this helps.

                        Advansys Support

                        #6448
                        Anonymous

                          sEmail = GroupWise.AddressBookResolveFullName(sMail, “”)

                          worked like a charm. Thanks.

                          #6451
                          rstarr
                          Participant

                            Hate to push my luck, but this all seems easy for you. I want to make sure that the disclaimer only gets inserted only once since it is obnoxiously long, so I want to key off of the Send event and search the BodyText of the message for language particular to part of my disclaimer, i.e.”disclaimer/confidentiality”. If the text is found then I don’t want to insert it again.

                            I don’t see an ItemFindText method in the GroupWise tokens API, so I have tried to simply extract the message body into a variable using the ItemGetText method and then check the variable for “disclaimer/confidentiality.” I am stuck again. Here is my code:

                            Sub Main(Client, GWEvent)
                            Dim FileObj
                            Dim sMsg

                            On Error Resume Next
                            If ValidMsg(sMessage) And (GWEvent = “GW#C#SEND”) Then
                            Set FileObj = CreateObject(“Scripting.FileSystemObject”)
                            call GroupWise.FocusSet(fcsMessage, “”)
                            ‘None of the following 3 work and all I get is a generic ‘an error has occurred at column 0’:
                            sMsg = Client.ClientState.CommandMessage.BodyText
                            sMsg = GroupWise.ItemGetText(Client.ClientState.CommandMessage.MessageID, fcsMessage)
                            sMsg = GroupWise.ItemGetText(Client.ClientState.CommandMessage.MessageID, Message)

                            If (Instr(1, sMsg, “disclaimer/confidentiality”) = 0) Then
                            msgBox “Did not find disclaimer language”
                            Else
                            msgBox “Found the disclaimer language”
                            ‘ End If
                            Set FileObj = Nothing
                            End if
                            End Sub

                            Loading the whole Body Text into a variable seems burdensome.

                            This code might also be handy to be sure that the signature block doesn’t get inserted multiple times. Thanks for whatever you can suggest.

                            #6456
                            Support 1
                            Participant

                              You can do this in several ways; using a script variable to store the message body is one reasonable option.

                              Here is another way. Find in the Token API looks for text in the message body. If successful, Find also selects the text. Unfortunately Find does not return True/False. But as the following code shows, we can copy the selected text to the clipboard and do a string comparison.

                              --------------------------------------------------------------------------------
                                dim iText
                              
                                ' Set up the search text
                                iText = "disclaimer/confidentiality"
                              
                                ' Clear the clipboard
                                Utilities.ToClipBoard("")
                               
                                ' Set the focus to message body and point to the beginning of the first line.
                                call GroupWise.FocusSet(fcsMessage, "")
                                call GroupWise.PosTextTop
                               
                                ' Find the text
                                call GroupWise.Find("", "", iText, _
                                  fsdForward, matSubText, matSubText, matSubText)
                               
                                ' Copy to clipboard
                                call GroupWise.EditCopy
                               
                                If (InStr(1, Utilities.FromClipBoard(), iText, vbTextCompare) > 0) then
                                  call MsgBox("Found the disclaimer language.")
                                else
                                  call MsgBox("Did not find disclaimer language.")
                                end if
                              --------------------------------------------------------------------------------
                              

                              I hope this helps.

                              Advansys Support

                            Viewing 12 replies - 1 through 12 (of 12 total)
                            • You must be logged in to reply to this topic.