xBaseJ Mailer

This Java application reads an XML file that is a template used to send out emails. It will pass through a dbf file and can select particular records using several filtering mechanism. Of primary importance in the dbf file is a field that contains valid email address.

Sample Program

This is a sample xml file that sends out a message to tell the user that there registration has expired. The message has a pdf file attached so the user can find out more information. !DOCTYPE mail SYSTEM "xBaseJMailer.dtd"> <mail file="c:/file.out" runType='send'> <server userid="jusery@mailhomenews.com" password="*^^^^**">mail.mailhomenews.com</server> <database filename="customer.dbf"> <index filename="customer.ndx" startat="xBase" endAt="xBaseJZ"/> <filter> <fieldtest compare="${lastdate}" operator="LT" to="${currentDate}"/> <and/> <fieldtest compare="${lastdate}" operator="NE" to=" "/> </filter> </database> <to>${email_id}</to> <from>jusery@mailhomenews.com</from> <subject>Registration ${reg_no} Expired.</subject> <text dateFormat="MMMM dd, yyyy"> ${firstNm}, As of ${lastdate} your registration ${reg_no} has terminated. See attached pdf file for more information on renewing your registration. Joe </text> <attachFile filename="c:/renewal.pdf"> </mail> To run the sample program, we call the mailer and pass it the current date and the name of the above file (theMailerFile.xml). The current date passed is checked against a database field named lastdate. To show some structure to the control logic of the filter node a second test is used to eliminate dates that are not yet set. java xBaseJ.xBaseJMailer -DcurrentDate="20051231" theMailerFile.xml The resulting mail maybe as follows: Message-ID: <6603598.1125520506687.JavaMail.jusery@mailhomenews.com> Date: Wed, 31 Aug 2005 16:35:06 -0400 (EDT) From: jusery@mailhomenews.com To: BradSmith@SmithAndBrad.com Subject: Registration xBase000202 Expired. Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_0_28311783.1125520506562" X-xBaseJMailer: xBaseJ/xBaseJMailer ------=_Part_0_28311783.1125520506562 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Brad, As of January 22, 2005 your registration xBase000202 has terminated. See attached pdf file for more information on renewing your registration. Joe ------=_Part_0_28311783.1125520506562 Content-Type: application/pdf; name=renewal.pdf Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename=renewal.pdf JVBERi0xLjMKJcfsj6IKNSAwIG9iago8PC9MZW5ndGggNiAwIFIvRmlsdGVyIC9GbGF0ZURlY29k ZT4+CnN0cmVhbQp4nK1aXW/jNhZF4q/YCWQlYmSP04wpyx3bO2ONSEmUOO2+LLBYoOhLu3kb7VOL LbboBGj2Yf/+kpRIifpwrLERJDbJe4/Icw/JSyp/Qt/DIfT5j/zyy5fJx59j+Nt/J6Ia/vyP/MvL b5M/J6GHCCGxqCh//+UL/NsTc6QQI/j074nvUZogPxCNCEaIGVMK4zDwQvj0ZbK9uOz1B8PR7ul3 5oUQpMrLzyERDOPQwwHzYt4xVm7c5+9Pk58mIfzfBMEf2O9/mKvvBwlNCIbNX9k4UBIRL4KBjxL2 8UWWMSWYffwx+ecEo7jULkql1qp/2brUnnvU/RWhr/OIgmZGSCQYIZR4SUHkZW8wGCpaOlChuirL

Passing External Variables

By using one or more properties files you can pass other variable information to the mailer. For instance, say you needed to hide the server information. We could use a properties file to pass the three fields server id, user id and password. As follows: <mail file=... <property filename="server.properties"/> <server userid="${userid}" password="${password}">${serverid}</server> ... </mail> To match the above example the server.properties file reads as follows: serverid=mail.mailhomenews.com userid=jusery@mailhomenews.com password=*^^^^**
Below is more information on variables.

XML File Nodes and Contents

The DTD

<?xml version="1.0" encoding="UTF-8"?> <!ELEMENT mail (properties?, server, database, (to | cc | bcc), from, subject, text, attachFile?)> <!ATTLIST mail file CDATA #IMPLIED runType (parse | test | send) "test" > <!ELEMENT properties EMPTY> <!ATTLIST properties filename CDATA #IMPLIED > <!ELEMENT server (#PCDATA)> <!ATTLIST server userid CDATA #IMPLIED password CDATA #IMPLIED > <!ELEMENT database ((index|tag)?,(filter)*)> <!ATTLIST database id CDATA #IMPLIED filename CDATA #REQUIRED skipDeleted (Y | N | T | F) "Y" > <!ELEMENT index EMPTY> <!ATTLIST index filename CDATA #REQUIRED startAt CDATA #IMPLIED endAt CDATA #IMPLIED > <!ELEMENT tag (#PCDATA)> <!ATTLIST tag name CDATA #REQUIRED startAt CDATA #IMPLIED endAt CDATA #IMPLIED > <!ELEMENT filter ( (fieldtest|filter), ((and | or ),(fieldtest|filter))* ) > <!ELEMENT fieldtest (#PCDATA)> <!ATTLIST fieldtest compare CDATA #REQUIRED operator (LT | LE | EQ | NE | GT | GE) #REQUIRED to CDATA #REQUIRED > <!ELEMENT and EMPTY> <!ELEMENT or EMPTY> <!ELEMENT to (#PCDATA)> <!ELEMENT cc (#PCDATA)> <!ELEMENT bcc (#PCDATA)> <!ELEMENT from (#PCDATA)> <!ELEMENT subject (#PCDATA)> <!ELEMENT text (#PCDATA)> <!ATTLIST text dateFormat CDATA #IMPLIED > <!ELEMENT attachFile (#PCDATA)> <!ATTLIST attachFile filename CDATA #REQUIRED >
Element Parent Node
or
Attribute
Contents Description
mail   (properties?, server, database, (to | cc | bcc), from, subject, text, attachFile?)>
  file name of file that messages are written, use for debugging defaults to system console file.
  runType parse | test | send parse - runs only parse step,
test - runs through database but does not generate mail
send - runs and sends the messages
properties, optional mail    
  filename any properties file to load variable data to be used by application
server mail e-mail server id enter the name of the e-mail server here
may be passed through run time argument -Dserver=
  userid user id associated with e-mail server may be passed through run time argument -Duserid=
  password password associated with user id may be passed through run time argument -Dpassword=
database mail ((index|tag)?,(filter)*)
  id id to associate variables
  filename name of dbf file REQUIRED
  skipDeleted Y | N | T | F ignore records marked deleted, default is "Y"
index, optional database name of index file associated with database file
  filename name of ndx file REQUIRED
  startAt string to start the search on if not used starts at the first indexed record
  endAt string to stop processing at if not used goes to end of index
tag, optional database name of a tag in a mdx file
  name tag name in mdx file REQUIRED
  startAt string to start the search on if not used starts at the first indexed record
  endAt string to stop processing at if not used goes to end of index
filter, optional, one or more database ( (fieldtest|filter), ((and | or ),(fieldtest|filter))? By using a filter within a filter you generate a bracketing of test logic.
If the filter logic is true the current record is skipped.
fieldtest, optional, one or more filter no data used
  compare value or variable to compare against REQUIRED
  operator LT | LE | EQ | NE | GT | GE REQUIRED
  to value or variable to compare against REQUIRED
and filter no data used
or filter no data used
to mail e-mail id mail is sent to
cc mail e-mail id mail is sent to using the cc mail attribute
bcc mail e-mail id mail is sent to using the cc mail attribute
from mail sending e-mail id
subject mail text for subject line
text mail message text
  dateFormat String specifying how date fields are to be formatted Uses the Java SimpleDateFormat method
Time portion of date formatting is not used.
attachFile, optional mail name of file to attach to e-mail
  filename name of the file to attach REQUIRED

Variables

Variables are identified by the ${} construct. Place the variable name between the brackets, e.g. ${dateStart}.
Variables are built three ways.
  1. Passed through a property file. Property files are a name/value pair defined by the construct name=value. Names passed this way are case sensitive.
  2. Fields in the database. For instance if a database had three fields: name, dateStart and dateEnd the mail process would access them as ${name}, ${dateStart} and ${dateEnd}. These variable names are not case sensitive.
  3. Passed using run-time arguments.
    e.g. java xBaseJ.xBaseJMailer -DdateStart=20080409 -Duserid=myemailaddress myMailMessage.xml

Required Packages

Besides the xBaseJ package you will need to download these packages.
  1. a Java based XML parser - we recommend Xerces
  2. the log4j package
  3. if you're using older version of java you may need the java mail and Java Activation Framework packages.

Additional Files

The package uses an additional file named mimeType.properties. This property file is used to associate the attached file with a mime type. Basically the file extension (any character after the last period in the file name) maps to the mime type. You may change the file to suit your needs.