Search This Blog

Loading...

Thursday, 29 January 2015

Call a script to set the subject of an email

The $CALL$ Macro

We just uploaded a new beta for WatchDirectory that has a very nice new feature: The $CALL$ macro which allows you to set (part of) the subject and/or body text of your emails.

This new feature allows you to call a batch script and use its "output" inside your emails.

Example: add the word "Error" to the subject when detected files contain the word "Error"

You could use the following text for the email subject:

$CALL:C:\Scripts\GetSubjectPrefix.bat$ detected file %WD_FILE_N%

The task will call the above script and will set all Environment Variables related to the detected file. Below is the GetSubjectPrefix.bat script:

rem use the FINDSTR command to look for the string Error inside the detected file
FINDSTR /I "Error" "%WD_FILE%"
IF %errorlevel% EQU 0 GOTO :ErrorFound
GOTO :ErrorNotFound

:ErrorFound
ECHO [ERROR] > "%WD_RESULTFILE%"
GOTO :EOF
:ErrorNotFound
ECHO [OK]  > "%WD_RESULTFILE%"
GOTO :EOF

Download

The download for this beta is available on our forum.

No comments: