Parker Software Ltd Homepage
Forum Home Forum Home > ThinkAutomation Business Process Automation > Scripting
  New Posts New Posts RSS Feed - Reading in text files to move email attachments
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Reading in text files to move email attachments

 Post Reply Post Reply
Author
Message
Ascidious View Drop Down
New User
New User


Joined: 15 Mar 2019
Location: Ohio
Points: 2
Post Options Post Options   Thanks (0) Thanks(0)   Quote Ascidious Quote  Post ReplyReply Direct Link To This Post Topic: Reading in text files to move email attachments
    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
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 11.05
Copyright ©2001-2016 Web Wiz Ltd.

This page was generated in 0.047 seconds.