# 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 {
public:

// 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
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:

http://www.chris-lott.org/resources/cstyle/Wildfire-C++Style.html

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

http://mercurial.selenic.com/

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

http://bitbucket.org

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
instructions.

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

You must create three test-case mail messages for your
driver. Each of these should be addressed to a different
mailhost. I suggest using cs.pdx.edu 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.

## Submission

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