Watch a Directory as a Service
Previous Topic  Next Topic 

Purpose

 

This example demonstrates how to use the watch directory features of NetMailBot while running NetMailBot as a Windows Service. 

Specifically, a directory is watched for new files, when new files are found, they are sent to the recipient as an email attachment. After the email is sent, the files in the directory being watched are moved to the specified directory. 

Additional Prerequisites

 

Prepared Example Files

 

 

The .ini file (discussed below) in this example uses full paths and assumes that the .zip file has been expanded to C:\tmp. Therefore, download this .zip file to C:\tmp on your hard drive or edit the .ini file to reflect wherever you unzip the archive.

 

The archive contains ten files:

 

 

File Contents

 

This is the content of the NMBService.ini file:

 

[Settings]

ServiceName = NMBService

ProcCount = 1

CheckProcess = 60

[Process0]

CommandLine = C:\Program Files\NetMailBot\netmailbot -to email@domain.com -from email@domain.com -server localhost -watchdir "c:\tmp\watch" -watchmoveto "c:\tmp" -logfile "c:\tmp\log.txt"

WorkingDir = C:\Program Files\NetMailBot

PauseStart = 0

PauseEnd = 3000

UserInterface = No

Restart = No

 

All of the .bat files invoke NMBService.exe with various parameters to effect the desired outcome.

 

This is the content of the NMBStart Service.bat file:

 

NMBService -r NMBService

 

This is the content of the NMBStop Service.bat file:

 

NMBService -k NMBService

 

This is the content of the NMBService Install.bat file:

 

NMBService -k NMBService

NMBService -u

NMBService -i

NMBService -r NMBService

 

@pause

 

This is the content of the NMBService UNInstall.bat file:

 

NMBService -k NMBService

NMBService -u

pause

 

Steps

 

  1. Unzip the DirectoryWatchAsAService.zip file into C:\tmp. This file contains no internal directories. The files listed above will appear directly in C:\tmp.
  2. Open Notepad and edit the file NMBService.ini, changing the following:
  1. Invoke the batch file "NMBService Install.bat" to install the Windows Service helper program.
  2. Ensure that the service and NetMailBot are running. Open Task Manager, select the "Processes" tab, and look for the two processes "netmailbot.exe" and "NMBService.exe".
  3. Go to the directory "c:\tmp\watch" to ensure the files no longer exist and check the directory "c:\tmp" to ensure the attach*.* files now exist there.
  4. Check your email account Inbox for an email containing the file attachments.
  5. To uninstall the service, execute the batch file "NMBService UNInstall.bat".