Run as Windows Service and Watch a Directory

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.

  • Requirements
    • Windows NT/2000/XP/2003 only.
    • Adminstrator privelege to install and run a Windows Service.

  • Example Download
    A working example can be downloaded, so that you can follow along with the example:
     Click Here (watch.zip 24KB)
    The downloadable example is a zip file that contains 4 files:
    • NMBService.exe - The NetMailBot helper program for running NetMailBot as a Windows Service
    • NMBService.ini
    • NMBService.log
    • NMBStart Service.bat
    • NMBStop Service.bat
    • NMBService Install.bat
    • NMBService UNInstall.bat
    • watch\attach1.txt - A file to attach
    • watch\attach2.txt - A file to attach
    • watch\attach3.txt - A file to attach

    Instructions for Download and Installation

    • Download the example zip file and save it to your hard drive
    • Create a directory on your C drive named "tmp"
    • Unzip all of the files in the example zip file into the newly created directory c:\tmp. Ensure that the attach*.txt files are all in the directory c:\tmp\watch. If they are not, create a text file with Notepad and save it in that directory.

  • Steps
    1. Open Notepad and edit the file NMBService.ini, changing the following:
      • Ensure the path to the NetMailBot is correct. By default, it is C:\Program Files\NetMailBot
      • -server to your mail server.
      • -to to an email address where the message can be forwarded.
      • -from to an email address that can be used as the from email address.
      • The parameter -watchdir "c:\tmp\watchdir" instructs NetMailBot to watch the directory "c:\tmp\watchdir" for files to send as attachments to the -to email address.
      • The parameter -watchmoveto "c:\tmp" instructs NetMailBot to move the files in the directory "c:\tmp\watchdir" to the directory "c:\tmp" after the email is sent.
    2. Execute the batch file "NMBService Install.bat" to install the Windows Service helper program.
    3. 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".
    4. 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.
    5. Check your email account Inbox for an email containing the file attachments.
    6. To uninstall the service, execute the batch file "NMBService UNInstall.bat"