"Events and Messages : Reactive" - Send email on upload to a specific folder

This example illustrates how to send a mail notification after a file has been uploaded to a specific folder. It also does a virus scan before sending the mail.
It uses a separate script to generate the email data. This is done to get correct linefeeds in the email format. It also acts as a template for the email.

Event in zFTPServer:
OnUploadEnd

Message in zFTPServer:
Closing data connection.%EXECUTE("C:\Scripts\MailOnUploadEnd.cmd" "%LOCAL_FILENAME%" "%FTP_FILENAME%")%

Contents of file "C:\Scripts\MailOnUploadEnd.cmd":
	@echo off
	REM Filenames may need special character codes.
	chcp 1252

	REM Virus scan the file, only send mail if the file still exists after the scan.
	"C:\Program Files\AVG\AVG2012\AVGSCANX.EXE" /HEUR /ARC /CLEAN /TRASH /SCAN=%1

	IF EXIST "%1" (
		REM Only send mail for a specific folder.
		SET FOLDER_FILTER=\Share this\
		SET FOLDER_UPLOAD=%~p2

		IF "%FOLDER_FILTER%"=="%FOLDER_UPLOAD%" (
			C:\Scripts\MailTemplate.cmd %2 | C:\Scripts\msmtp\msmtp.exe mailinglist@example.net
		)
	)

Contents of file "C:\Scripts\MailTemplate.cmd":
	@echo off

	setlocal enableDelayedExpansion
	set NL=^


	REM Two empty lines required for newlines to work
	echo SUBJECT:New file uploaded %~nx1!NL!
	echo And here's a link to it.!NL!http://www.test.com/%~nx1!NL!
	EndLocal