Assignment 2 - Write a Mail-Sending Program

Assignment 2 - Write a Mail-Sending Program

Draft 2, 25 October 2010

Designing, implementing, constructing and evaluating "small"
(200-500 line) standalone programs is a task that should be
easy for any developer. In this assignment, you will do
such an exercise as the first step in constructing your
team's Mail User Agent (MUA). In the process, you will get
set up with the tools and process you need to develop. You
will also learn to find and read standards documents, and to
code to a required coding standard.


Write a program that sends an email message to a single
recipient. The program must be constructed as follows:

Write a C++ object conforming to the following interface:

  #include <string>

using namespace std;

class MailSender {

// Set up the class for sending the given file as email.
// The file should contain an RFC-822 formatted email
// message, whose correctness will be assumed by this object.
MailSender(string &filename);

// Actually send the email to the given host
// with the given source and recipient. Returns
// 0 on success, and -1 on failure. In the
// case of failure, the global variable errno
// will be set to indicate a failure code.
virtual int send(string &host_to,
string &envelope_from,
string &envelope_to) = 0;

The object should send the email over a TCP socket to the
SMTP port on the host specified by name or IP address in the
first argument, and use the given envelope addresses during
the conversation with that host. The object should throw
an appropriate standard exception on error. Your implementation
of the SMTP transaction must adhere to RFC821.

Now write a command-line driver for this object. The driver
should accept a single filename argument; the file should
contain an email message with a single From: and To: and no
Cc: lines. The To: address should be a simple username@hostname
address, although it may have a comment part as per RFC 822
et al. The driver should dig envelope information out of the
mail message, and pass this information to the client object.

You must follow the course coding style. See:

You must use Mercurial as your source code management system. See:

You must have a public Mercurial repository for your
project. You are encouraged to use Bitbucket as your public
Mercurial repository host. See:

You must include a Makefile sufficient to build the project.
You must include a README with a manifest (list of project
files and their meanings) and sufficient build and run

You must make your code publically available under the MIT License. See:

Place the MIT License in a file called COPYING in your
project, and place a reference to this file at the top of
each file in your project, just below your copyright notice.

You must create three test-case mail messages for your
driver. Each of these should be addressed to a different
mailhost. I suggest using and two public email
providers such as gmail and yahoo email. Of course, you
should be able to receive email through these providers to
verify success.


Submit the URL of your Mercurial project repository to
Moodle. Remember that you will be evaluated solely on the
contents of this repository.


The other members of your team will pull your repository
using the URL you supplied, inspect your work, test the code
against both your test cases and theirs, write a paragraph
of feedback, and assign your work a score between 0 and 10
based on their evaluation of the overall quality of your
project. We will normally assign points as the mean of
these scores. Randomly, or if there is a major discrepancy
in scores, the course TA or I may inspect your work. If so,
we will assign your work a score based solely on our