This example demonstrates how to send an email using the mail merge features in NetMailBot, specifically how to set the friendly name of the recipient. The database used is a text file in CSV format (comma delimited file) 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.
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 three files:
- MailMergeCSVFriendly.bat - The batch file that will instruct NetMailBot to send the email message.
- data.txt - The CSV file that contains the mail merge data.
- body.txt - The text file that will be the email message body.
This is the content of the batch file:
netmailbot -to email@example.com -from firstname.lastname@example.org -subject "Mail Merge Example" -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 "email" -dbreplacementids "<<firstName>>=firstName,<<lastName>>=lastName,<<tracking>>=tracking" -bodyfile "body.txt" -personalize -tofriendly "<<firstName>> <<lastName>>" -test -debug
The data file contains:
Here is the body.txt file:
Dear <<firstName>> <<lastName>>,
Your tracking number is <<tracking>>
- Unzip the MailMergeCSVFriendly.zip file. This will produce a directory called "MailMergeCSVFriendly". 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 "MailMergeCSVFriendly.bat". Note these important parameters used in the batch file:
- Change the parameters: -to email@example.com -from firstname.lastname@example.org 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 "email" instructs NetMailBot to use the data in the "column" named "email" to address the message to the data contained in that column for the current row.
- The parameter -bodyfile "body.txt" instructs NetMailBot to use body.txt as the email message body. This time we have used a relative path; that is, NetMailBot will look for a file "body.txt" in the same directory as the batch file. Previous examples used a full path as in "C:\tmp\body.txt". In the body.txt file, you will see:
Dear <<firstName>> <<lastName>>,
Your tracking number is <<tracking>>.
The items in double-angle brackets ("<<" and ">>") are "replacement IDs" which are explained next.
- -dbreplacementids "<<firstName>>=firstName,<<lastName>>=lastName,<<tracking>>=tracking" 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 <<firstName>> with the data contained in the column named "firstName".
- -personalize instructs NetMailBot to make the replacements. Without this parameter specified, NetMailBot will not perform any replacements.
- -tofriendly "<<firstName>> <<lastName>>" instructs NetMailBot to append a friendly name to the "To:" addressing field using the replacement IDs listed.
- -test instructs NetMailBot to only perform a test of these operations; no actual emails will be sent.
- 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 with the -to parameter should each receive a personalized text message. The "To:" field should include a "friendly" name (e.g. "John Smith") as well as the usual "unfriendly" email address (e.g. "email@example.com").