DOS Environment Variables in Message Bodies
Previous Topic  Next Topic 



This example demonstrates how to refer to DOS environment variables within message bodies so that the values held in the environment variables can be "expanded" into the message bodies on-the-fly.


This technique could conceivably work anywhere in the NetMailBot batch file, as long as the resulting values after "expansion" make sense within the NetMailBot command line.


NOTE: This also works directly on the command line.


Additional Prerequisites


Using this feature requires familiarity with DOS environment variables.


Prepared Example Files



The archive contains one file:



Batch File Contents


This is the content of the batch file:


netmailbot -to -from -subject "Expanding Environment Variables on %date%" -server localhost -logfile c:\tmp\log.txt -body "This message was sent on %date% at %time%."




  1. Unzip the file. This will produce a directory called "EnvVarExpansion". Open this directory.
  2. Open Notepad and edit the batch file "EnvVarExpansion.bat". Change the values of the parameters -to, -from, and -server to a test recipient of your choosing, your email address, and your mail server.
  3. Invoke the batch file. You will see that the environment variable name substitution occurs first, before the batch file is used to run NetMailBot. The result of this expansion is automatically echoed to the console (only the first line below is typed in; the rest comes back at you just before NetMailBot starts up):




D:\EnvVarExpansion>netmailbot -to -from -subject "Expanding Environment Variables Demonstration" -server mysmtp -logfile c:\tmp\log.txt -body "This message was sent on Sun 07/25/2004 at 15:59:52.32."


  1. NetMailbot should start up and, upon finishing, the email address specified with the -to parameter should receive an email message containing the actual date and time that the message was sent instead of the environment variable names %date% and %time%.