Q: If I use Filemover to move or copy a txt file, is it possible to get the contents of that file, and then maybe include it in a Rule Event e-mail? I would like it as the e-mail body please.
A: Yes this is possible. We’ll use some Pascal Script to read the content of the text file into a variable (%VSA). This variable will be used in the email setup of the SMTP destination.
In our example we’ll scan for text files in a local Windows folder.
The ‘Include File Name’ filter is set to *.txt because we only want to pick up text files.
Important, set the Function > Destination Option to ‘Exit Cyclus on Error’. The reason is that we are going to use two destinations. The first destination which is a Pascal Script will read the content of the text file in to the %VSA variable. If this doesn’t succeed then we should not go to the second ‘SMTP’ destination. We only want to sent the email (SMTP) if the read content of the source text file is successful.
As previously described, we are going to use two destinations. Important, the first one must be the ‘Pascal Script’ destination.
Var tmpFile: String; tmpList: TStringList; Begin psExitCode:= 0; // ... add your code here tmpFile := psFilePath + psFileName; tmpList := TStringList.Create; Try Try tmpList.LoadFromFile(tmpFile); psVSA := tmpList.Text; psExitCode := 1; Except psLogWrite(1, '', 'Error loading ' + tmpFile); End; Finally tmpList.Free; End; End.
The second destination is SMTP. Some screenshots of the setup we used. We added the %VSA varaible in the Body of the email.
RunTime log result:
Received email with the content of the text file in the body of the email:
#Filetransfer #Filemanagement
If you need any info about this request, please let us know.
Best regards,
Limagito Team