Project 2 - A Customizable Email List Program

Due Friday 3/6 - 5PM

Deadline extended to 3/9 - 1PM

The goals of this project are as follows:
  • practice algorithmic thinking
  • practice text processing
  • practice file input and output
  • become familiar with using third-party libraries and setting the classpath
  • become familiar with providing command line input
  • become familiar with the data structures provided in java.util
For this project, you will build a program that sends a customized email message to a list of recipients.  The message to be sent will be stored in a text file, and may contain variables denoted by the dollar sign ($).  The values for the variables, along with the email address of each recipient, will be stored in a separate file. 
Example message file:

This is a test message for $name.  You own me \$$amount!

Example values/addresses file:

address =
name = Bob Smith
amount = 90

address =
name = Sally Sue
amount = 20

In the example above, the message "This is a test message for Bob Smith.  You owe me $90!" will be sent to and the message "This is a test message for Sally Sue.  You owe me $20!" will be sent to

A message may contain multiple variables.  A message may also contain the dollar sign.  The escape sequence \$ is used to denote that the dollar sign should appear literally. 

Here is an example message file.

Here is an example address file.

Requirements and Hints

  1. The program must accept the name of the message file, the name of the address file, and the 'from' email address as command line input.  From the command line, your program should be run as follows: java Driver -M messagefile.txt -A addressfile.txt -F From Eclipse, you can configure the command line parameters by choosing Run -> Open Run Dialog -> Arguments.  In the Program Arguments box, type -M messagefile.txt -A addressfile.txt -F and then run.
  2. Use the javax.mail API to send messages.
    1. Download and unzip the javax.mail implementation from
    2. Download and unzip the activation framework from
    3. Include jaf-1.1.1/activation.jar and javamail-1.4.1/mail.jar in your classpath
      1. In Eclipse, right click the mailer project and select Properties.  Select Java Build Path on the left.  Select Libraries.  Select Add External Jars.  Navigate to the jar and click Open.  Do this for each jar.
      2. From the command line, use -cp option.  Example: javac -d bin -cp ~/Desktop/javamail-1.4.1/mail.jar:~/Desktop/jaf-1.1.1/activation.jar src/*.java
  3. The javadoc for the javax.mail package contains a good example of how to send mail using java:  
    1.     Properties props = new Properties();
      props.put("", "my-mail-server");
      props.put("mail.from", "");
      Session session = Session.getInstance(props, null);

      try {
      MimeMessage msg = new MimeMessage(session);
      msg.setSubject("JavaMail hello world example");
      msg.setSentDate(new Date());
      msg.setText("Hello, world!\n");
      } catch (MessagingException mex) {
      System.out.println("send failed, exception: " + mex);
    2. You may use as your SMTP server. 
  4. The message may contain any characters, including the $.  If the $ is to appear literally, it must be escaped as \$.
  5. At minimum, your program must handle the following erroneous situations:

     Program Response
    The message or address file does not exist.
    Exit the program gracefully.
    The command line parameters are specified incorrectly.
    Exit the program gracefully.
    The address file is malformed.  For example, a particular variable is not specified.
    Print an appropriate message and do not send an email to the recipient.
    The SMTP server cannot be contacted.
    Print and appropriate message and exit the program gracefully.

Recommended Design and Implementation

It is recommended that you implement your project in stages as described below:
  • Stage 1 - The program works as described above with the exception that variables and escape sequences in the message file are not processed.  A simple text file is read in and sent to a list of email addresses specified in the address file. (worth 70% credit)
  • Stage 2 - The program works as described above with the exception that escape sequences are ignored.  A text file is read in and processed to extract the variables.  The customized message, including the variable values, is sent to each recipient. (worth 90% credit)
  • Stage 3 - The program works as described above, including escape sequences. (worth 100% credit).
  • Stage 4 - Use SSL (Secure Socket Layer) for communication.  See to get started.  (extra credit)
There is no API that you are required to implement for this project.  The recommended design is as follows:
  • Msg - A class that processes the file containing the message and maintains data structures containing the message and the variable names.  One option is to maintain two ArrayLists.  One contains an item for each portion of the message and one contains the variable names.  For the message "this is message $num for $name", the message list would contain the items [this is a message ] [for] and the variables list would contain [num] [name].  The ith variable value will go after the ith message item.
    • Note: Do not use Message as a class name.  You will end up with a conflict with the javax.mail.Message class.
  • Values - A class that processes the file containing the addresses and variable values and maintains data structures containing the information.  One option is to maintain an ArrayList of HashMaps.  Each item in the ArrayList is a HashMap that maintains the record for a particular recipient.  THe HashMap contains key, value pairs where the key is the variable name and the value is the value.
  • Mailer -  A class that contains the logic of sending appropriate messages.  This class will need to have access to the data structures maintained by Msg and Values.
Submission Instructions