This post will describe how you can configure WatchDirectory's Email Task to receive an email when a directory has no activity for some time.
The Problem
WatchDirectory and its Email Task are most often used to send email when new files are created or changed. To make it send an email when "nothing happened" might seem easy, just select the QUIET option on the Events page and WatchDirectory will "trigger" when no changes are detected.
If you only select "QUIET" as the event, you will soon find you also receive emails even if there is activity (new files) in the monitored directory. Why is this?
The issue is that "QUIET" needs other events to "compare against". When another event happens, for example "FILENEW" - a new file is created, WatchDirectory sets a timer for the QUIET event. If there is another event before the timer times out, the timer is reset again.
So, if you want to receive an email when nothing happened for some time, you must enable both the QUIET and the FILENEW events. Obviously, now you will also receive emails when new files are created.
No Email for New Files
Here is how you can configure WatchDirectory to prevent those emails for new files.
First, you must make sure the email body has some unique text to distinguish between emails for the QUIET event (nothing happened) and the emails for FILENEW (new files are detected). Enter something like this at the bottom of the message body:
%WD_CONFIG%-%WD_REASON%
The above are 2 Environment Variables you can use with the Email task. %WD_CONFIG% is replaced by the name of your task (for example "NotifyNoActivity") and %WD_REASON% is replaced by "what happened" (QUIET or FILENEW).
Filter Email
Close the settings of the task and select WatchDirectory's menu
"View -> Email -> Email Settings".
At the bottom of the window that opens click "Filter Email" and the window to the left will open.
On this window you can enter (partial) subjects and message body strings that will prevent WatchDirectory sending those emails. Every email, for all tasks you create that has the text "NotifyNoActivity-FILENEW" in its body, will not be sent.
No comments:
Post a Comment