Purpose
This example demonstrates how to send an email using the mail merge features in NetMailBot, specifically how to personalize the fields "To:", "From:", "Subject:", and the filename of the email message body. The scenario used here is reporting the results of a contest or sweepstakes to winners, losers, and those who have won a tie game. The message body is loaded from a file that is dynamically assigned based on win/lose/tie data in the .csv file (the database used is a text file in CSV format which contains some sample data).
NOTE: You should change the email addresses in the CSV text file to your own email address(es) before running a test.
Additional Prerequisites
Windows 95 / 98 Users: Make sure you have the latest ODBC drivers installed on your machine.
Prepared Example Files
The -bodyfile parameter in NetMailBot uses full paths. We have assumed a particular path as shown in the batch file contents below. Therefore, download this file to C:\tmp on your hard drive or edit the parameters to reflect wherever you unzip the archive.
The archive contains five files:
- MailMergeCSVCustomBody.bat - The batch file that will instruct NetMailBot to send the email message.
- data.txt - The CSV file that contains the mail merge data.
- winner.txt - A text file that is a message body.
- loser.txt - A text file that is a message body
- tied.txt - A text file that is a message body
File Contents
This is the content of the batch file:
netmailbot -to ignored -from "<<from>>" -subject "<<subject>>" -server localhost -logfile c:\tmp\log.txt -dsn "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\tmp\;Extended properties=Text;" -dbquery "SELECT * FROM data.txt" -dbemailcolumn "to" -dbreplacementids "<<name>>=name,<<from>>=from,<<to>>=to,<<subject>>=subject,<<filename>>=filename" -bodyfile "c:\tmp\<<filename>>" -personalize -debug
The data file contains:
to,from,name,subject,filename
test@exclamationsoft.com,one@exclamationsoft.com,John Smith,You win,winner.txt
test@exclamationsoft.com,two@exclamationsoft.com,Mike White,You lose,loser.txt
test@exclamationsoft.com,three@exclamationsoft.com,Tom Blue,Tie game,tied.txt
Here is the winner.txt file, to illustrate the custom mail bodies used in this example:
Dear <<name>>,
This email is from <<from>>
This email is to <<to>>
The outcome of the game is: <<subject>>
Please pickup your prize!
Steps
- Unzip the MailMergeCSVCustomBody.zip file. This will produce a directory called "MailMergeCSVCustomBody". Open this directory.
- Open the data.txt file.
- Change all of the email addresses to your email address (for the purposes of this test run, they can all be the same).
- Save and close the data.txt file.
- Open Notepad and edit the batch file "MailMergeCSVCustomBody.bat". Note these important parameters used in the batch file:
- Change the parameters: -to test@exclamationsoft.com -from test@exclamationsoft.com to your own email address.
- Change the parameter: -server localhost to your own mail server.
- Note the use of -dsn "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\tmp\;Extended properties=Text;". This is a normal connection string that instructs NetMailBot on how to connect to the data.txt file. If you have not unzipped the archive to C:\tmp, you will have to edit this accordingly.
- -dbquery "SELECT * FROM data.txt" instructs NetMailBot to select all of the data from the file data.txt. This file is considered to be a pseudo database table.
- -dbemailcolumn "to" instructs NetMailBot to use the data in the "column" named "to" to address the message to the data contained in that column for the current row. This overrides the -to parameter, which is why we've put "ignored" in it.
- The parameter -bodyfile "C:\tmp\<<filename>>" instructs NetMailBot to replace <<filename>> with the data contained in the mapped column for the current row. In this example, each recipient will have a different message body. The first recipient will have the message body from the file "winner.txt", the second will have "loser.txt", and the third will have "tied.txt".
- -dbreplacementids "<<name>>=name,<<from>>=from,<<to>>=to,<<subject>>=subject,<<filename>>=filename" instructs NetMailBot to replace the strings in double-angle brackets with the data contained in the mapped column for the current row. For example, in the message body, NetMailBot will replace the string <<name>> with the data contained in the column named "name", and will replace the string <<from>> with the data contained in the column named "from", and so on.
- -personalize instructs NetMailBot to make the replacements. Without this parameter specified, NetMailBot will not perform any replacements.
- Invoke the batch file by double-clicking the icon or straight from the command line.
- NetMailbot should start up and, upon finishing, the email addresses specified indirectly via the -dbemailcolumn parameter should each receive a personalized text message.