QQ:928900200
Assignment 1 CS 436 W15
Mail User Agent / Server
Work on this assignment is to be completed individually
This assignment is divided into three parts. In the first part, you use telnet to manually send
email through an SMTP mail server. In the second part, you write a client program that
performs the same action. In the third part, you write a server program that simulates an email
server.
Part 1: Sending Email with Telnet
In this part you should try to send an email to yourself ([email protected]). This
means you need to know the host name of the mail server for your mail domain (here
uwaterloo.ca). To find out this information, you can query DNS for the MX record that
maintains information about your mail domain. The following command queries DNS for the
mail servers responsible for delivering mail to the uwaterloo.ca domain:
nslookup -type=MX uwaterloo.ca
Usually, there may be several mail servers in response to this command. Suppose that the name of one
of them is mxer.uwaterloo.ca. In this case, the following command will establish a TCP connection to
this mail server. (Notice that the port number 25 is specified on the command line.)
telnet mxer.uwaterloo.ca 25
At this point, the telnet program will allow you to enter SMTP commands, and will display the
responses from the mail server. For example, the following sequence of commands would
send email to yourself from your account myusername
HELO myusername
MAIL FROM:
RCPT TO:
DATA
SUBJECT: saying hello to myself
Hello to myself!
.
QUIT
The SMTP protocol was originally designed to allow people to manually interact with mail
servers in a conversational manner. For this reason, if you enter a command with incorrect
syntax, or with unacceptable arguments, the server will return a message stating this, and will
allow you to try again.
To complete this part of the assignment, you should send an email message to yourself and
verify that it was delivered.
Part 2: Sending Email with Java
Java provides an API for interacting with the Internet mail system, which is called JavaMail.
However, we will not be using this API, because it hides the details of SMTP and socket
programming. Instead, you should write a Java program that establishes a TCP connection
with a mail server through the socket interface, and sends an email message.
You can place all of your code into the main method of a class called EmailSender. Run your
program with the following simple command:
java EmailSender
where the inputs
You will include in your code the details of the subject and the particular email message you
are trying to send. Your program should read and display messages sent to and received
from the mail server. The following is a sample execution
220
***********************************************************************************
********************************************************
HELO n2limam
250 mailchk-m06.uwaterloo.ca Hello v1020-wn-157-157.campus-dynamic.uwaterloo.ca
[10.20.157.157], pleased to meet you
MAIL FROM: [email protected]
250 2.1.0 [email protected]... Sender ok
RCPT TO: [email protected]
250 2.1.5 [email protected]... Recipient ok
DATA
354 Enter mail, end with "." on a line by itself
SUBJECT: saying hello to myself
HELLO to myself!
.
250 2.0.0 t25FUn8p019830 Message accepted for delivery
QUIT
221 2.0.0 mailchk-m06.uwaterloo.ca closing connection
Connection closed by foreign hos
you must then be able to find the message in your mailbox.
Part 3: Receiving Email with Java
You should write a program that emulates a mail server. You can place all of your code into
the main method of a class called EmailServer. Run your program with the following simple
command:
java EmailServer
EmailServer should create a ServerSocket and bind it to port number
EmailServer and EmailSender should run on different machines e.g. on ubuntu1204-
004.student.cs.uwaterloo.ca and ubuntu1204- 006.student.cs.uwaterloo.ca respectively. A
sample execution would be:
...@ubuntu1204-004:~$java EmailServer 59991
...@ubuntu1204-006:~$java EmailSender ubuntu1204-004.student.cs.uwaterloo.ca 59991
whoever [email protected]
The EmailServer will have to act as a mail server, by recognizing commands, errors and
using the right reply codes:
Command
DATA
HELO
MAIL
FROM
QUIT
RCPT TO
Reply Code
354
250
250
221
250
Errors to be handled are those related to code 500 (unrecognized command) and 503 (out of
order command) as shown in the following sample execution:
220
***********************************************************************************
********************************************************
HELLOOO n2limam
500 5.5.1 Command unrecognized: "HELLOOO n2limam"
HELO n2limam
250 mailchk-m06.uwaterloo.ca Hello ubuntu1204- 004.student.cs.uwaterloo.ca
[129.97.167.42], pleased to meet you
DATA
503 5.0.0 Need MAIL command
MAIL FROM:
DATA
503 5.0.0 Need RCPT (recipient)
RCPT TO:
250 2.1.5
500 5.5.1 Command unrecognized: "SUBJECT:"
DATA
354 Enter mail, end with "." on a line by itself SUBJECT: saying hello to myself
Hello to myself!
..
...
QUIT
.
250 2.0.0 s14NYlwf023218 Message accepted for delivery QUIT
221 2.0.0 mailchk-m06.uwaterloo.ca closing connection
Procedures
Due Date
The assignment is due on March 25 2015, at midnight (11:59 PM).
Late submission policy: 10% penalty every late day, up to 3 late days. Submissions not
accepted beyond 3 late days.
Hand in Instructions
Submit all your files in a single compressed file (.zip, .tar etc.) using LEARN.
You must hand in the following files / documents:
– Source code files.
– README file: this file must contain instructions on how to run your program, which
undergrad machines your program was built and tested on, and what version of compilers
you are using.
Your implementation will be tested on the machines available in the undergrad environment.
Documentation
Since there is no external documentation required for this assignment, you are expected to
have a reasonable amount of internal code documentation (to help the markers read your
code). You will lose marks if your code is unreadable, sloppy, inefficient, or not modular.