Print Page | Close Window

Reading in text files to move email attachments

Printed From: Parker Software Ltd
Category: ThinkAutomation Business Process Automation
Forum Name: Scripting
Forum Description: General Email2DB scripting questions and sample scripts.
URL: http://www.parkersoftware.com/forum/forum_posts.asp?TID=9390
Printed Date: 07 Jul 2020 at 4:31pm
Software Version: Web Wiz Forums 11.05 - http://www.webwizforums.com


Topic: Reading in text files to move email attachments
Posted By: Ascidious
Subject: Reading in text files to move email attachments
Date Posted: 15 Mar 2019 at 12:32pm
Currently, im trying to create a trigger with a script. In this script I need to get who sent the email, and then read a text file, and compare to see if the domain of the email matches anything in the text file. If it does match, then move the attachments of that email to a specific folder. If it doesnt match anything in that txt file, then move on to the next text file and read it in, and so forth.

The folders that the attachments will always be named exactly the same as the text file that is being read from.

I am having trouble testing any of the code since I can't pass an email through the script while breaking at certain points.

If you have any insights on how to do what I need to do, then feel free to comment!

Here is the code I have as of now.

' Trigger Condition Script
' Use this script to control when a message Trigger is executed.

' Set the property ThinkAutomationTrigger to True in the Sub Main procedure to cause the Trigger to execute.
' You can create any number of new Sub Procedures and Functions.

' The ThinkAutomationMessage object can be used to access the current message properties.
' Use ThinkAutomationMessage.ExtractedFields("FieldName").Value to access/update extracted fields.
' Use AccountVariable("VariableName") to access/update Trigger variables.

Sub Main()
    ' commands start here
    ThinkAutomationTrigger = True

    Dim Attachment As clsMessageAttachment
    Dim vendorName As String
    Dim folder As String

    If ThinkAutomationMessage.Attachments.Count = 0 Then Exit Sub

    vendorName = ThinkAutomationMessage.From

    Dim startIndex As Integer
    startIndex = InStr(1, vendorName, "@")
    Dim domainAddress As String
    domainAddress = Mid(vendorName, startIndex + 1)

    Call AddToLog("Domain Address is: " & domainAddress)

    CheckName(domainAddress)




End Sub


Sub CheckName(domainAddress As String)

    Dim folderPath As String
    folderPath = Dir("C:\TestingAP\")


    Dim filestring As String
    Dim fileSys As Object

    Set fileSys = CreateObject("Scripting.FileSystemObject")


    Dim folderName As String
    Dim FSOLibrary As Object
    Set FSOLibrary = CreateObject("Scripting.FileSystemObject")

    Dim FSOFolder As Object
    Dim FSOFile As Object

    'Set the file name to a variable
    folderName = Dir("C:\TestingAP\")

    'Set all the references to the FSO Library
    'Set FSOLibrary = New Scripting.FileSystemObject
    Set FSOFolder = FSOLibrary.GetFolder(folderName)
    Set FSOFile = FSOFolder.Files




    'Use For Each loop to loop through each file in the folder
    For Each FSOFile In FSOFile

    Call AddToLog("FSOFolder is: " & FSOFolder & " FSOFile is: " & FSOFile)
        'Insert actions to be perfomed on each file
        'This example will print the file name to the immediate window
        Debug.Print FSOFile.Name

        If fileSys.FileExists(folderName + FSOFile.Name) Then
            Set filestr = fileSys.OpenTextFile(folderName + FSOFile.Name)
        End If
    Dim someArray As Variant

    Set someArray = Array(filestr)

    Dim i As Integer
    Dim position As Integer

    For i = 0 To UBound(someArray)
        position = InStr(1, domainAddress, someArray(i))

        If position > 0 Then
            For Each Attachment In ThinkAutomationMessage.Attachments
                FileCopy Attachment.Location, "C:/TestingAP/" & FSOFile & "/" & Attachment.Name

            Next
        Else
        End If

    Next

    Next

End Sub



Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.05 - http://www.webwizforums.com
Copyright ©2001-2016 Web Wiz Ltd. - https://www.webwiz.co.uk