/ Forums / Advansys Formativ / Creating Solutions with Formativ / Save message text to a file BEFORE sending…

  • Creator
    Topic
  • #3869
    wozza
    Participant

      Is there a way of saving an email, plus a list of its contents, to a nominated folder BEFORE the email is sent?

    • Author
      Replies
    • #6444
      Support 2
      Moderator

        This example saves the message information from a composing item and will work when integrated with the OnSend event.

        Let us know if you have any questions.

        Regards,

        Advansys Support

        '-------------------------------------------------------------------------------
        ' Formativ Solutions for GroupWise
        ' Save Composing Message
        ' Designed by: Formativ Business Solution Team
        ' Copyright (c) 2002 Advansys Corporation (www.advansyscorp.com)
        ' Version 1.01
        '
        ' Description:
        ' This applet will save the composing message details to a file.
        ' You need to provide the folder path where the file will be saved.
        '
        ' File name format: The file name will start with the subject,
        ' followed by the current date/time.
        ' For example: my subject_020314153920.txt
        ' where:
        ' my subject = The composing message's subject
        ' 020314153920 = yymmdd + time(24 hours) + current second
        '
        ' INTEGRATIONS: GroupWise mail OnSend.
        '-------------------------------------------------------------------------------

        dim FSO

        Const CAPTION = "Formativ Business Solutions"
        HRT = Chr(13) & Chr(10)

        ' Provide the root folder where the file will be saved
        '===============================================================================
        const FOLDER_PATH = "c:"
        '===============================================================================

        ' Do you want a confirmation message box when the applet creates the file
        ' TRUE - Yes, FALSE - No
        const CONFIRMATION_DLG = TRUE

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

        dim iMsgID
        dim iMsgText
        dim iSubject
        dim iAttachCounter

        set FSO = CreateObject("Scripting.FileSystemObject")

        ' Does the folder exist?
        if FSO.FolderExists(FOLDER_PATH) then
        ' Get the composing message ID
        iMsgID = GroupWise.ItemMessageIDFromView

        ' Make sure we have a composing message selected
        if (iMsgID = "X00") then
        ' Get the To, CC, BC, Subject and the body text
        iMsgText = iMsgText & "To: " & GroupWise.ItemGetText(iMsgID, itfTo) & HRT
        iMsgText = iMsgText & "CC: " & GroupWise.ItemGetText(iMsgID, itfCC) & HRT
        iMsgText = iMsgText & "BC: " & GroupWise.ItemGetText(iMsgID, itfBC) & HRT
        iSubject = GroupWise.ItemGetText(iMsgID, itfSubject)
        iMsgText = iMsgText & "Subject: " & iSubject & HRT & HRT
        iMsgText = iMsgText & "Message: " & GroupWise.ItemGetText(iMsgID, itfMessage) & HRT & HRT

        ' Does the message have any attachments?
        iAttachCounter = GroupWise.ItemAttachmentGetCount(iMsgID)
        if (iAttachCounter > 0) then
        ' Loop through the attachments to get the name
        for x = 0 to (iAttachCounter -1)
        iMsgText = iMsgText & "Attachment " & (x + 1) & ": " & GroupWise.ItemAttachmentGetName(iMsgID, x) & HRT
        next
        end if

        ' Save the text into a file
        if (iMsgText <> "") then
        call SaveTextIntoFile(iMsgText, iSubject)
        end if

        else
        call msgbox("Select a composing message and set the integration with OnSend.", vbInformation, CAPTION)
        end if
        else
        call msgbox(FOLDER_PATH & " - folder not exists.", vbCritical, CAPTION)
        end if

        set FSO = nothing

        End Sub


        '-------------------------------------------------------------------------------
        ' Save the text into a new file
        '-------------------------------------------------------------------------------
        sub SaveTextIntoFile(aText, aSubject)

        dim iFileName
        dim MyFile

        iFileName = FOLDER_PATH & RemoveInvalidCharacter(aSubject) & "_" & GetCurrentDateTime & ".txt"
        Set MyFile = FSO.CreateTextFile(iFileName, True)
        MyFile.WriteLine(aText)
        MyFile.Close
        set MyFile = nothing

        ' Do you need a confirmation message box?
        if CONFIRMATION_DLG then
        call msgbox("The following file created." & HRT & iFileName, vbInformation, CAPTION)
        end if

        end sub


        '-------------------------------------------------------------------------------
        ' Get the current date time to create a unique name
        '-------------------------------------------------------------------------------
        function GetCurrentDateTime

        dim iDay
        dim iMonth
        dim iYear
        dim iTime

        iDay = Day(date)
        if len(iDay) = 1 then
        iDay = "0" & iDay
        end if

        iMonth = Month(date)
        if len(iMonth) = 1 then
        iMonth = "0" & iMonth
        end if

        iYear = Year(date)
        if len(iYear) > 2 then
        iYear = right(iYear, 2)
        end if

        iTime = FormatDateTime(Time, vbShortTime)
        iTime = Replace(iTime, ":", "")
        iTime = Replace(iTime, ",", "")
        iTime = Replace(iTime, " ", "")

        GetCurrentDateTime = iYear & iMonth & iDay & iTime & Second(Now)

        end function


        '-------------------------------------------------------------------------------
        ' Remove invalid characters [The following characters are not acceptable as a file name]
        '-------------------------------------------------------------------------------
        function RemoveInvalidCharacter(aText)

        aText = replace(aText, "/", "")
        aText = replace(aText, "", "")
        aText = replace(aText, ":", "")
        aText = replace(aText, "*", "")
        aText = replace(aText, """", "")
        aText = replace(aText, "|", "")
        aText = replace(aText, "<", "")
        aText = replace(aText, ">", "")
        aText = replace(aText, "?", "")
        aText = replace(aText, ".", "")

        RemoveInvalidCharacter = aText

        end function
      Viewing 1 replies (of 1 total)
      • You must be logged in to reply to this topic.