Out: Wednesday, January 30, 2008
Due: Thursday, February 14, 2008
Preliminaries
Your task for this assignment is to write a simple Mail Transfer Agent
(MTA). An MTA is a program that relays email messages between
senders, receivers, and possibly other MTAs. MTAs are the servers
that process email messages in the Internet, passing them from the
sender's email client---or Mail User Agent (MUA)---and the receiver's
mail delivery agent. By far the most common MTA in use on the
Internet is the infamous sendmail program. Most of
sendmail's notoriety comes from its incredible complexity and
resulting never-ending discovery of security vulnerabilities. Don't
despair; your MTA will be considerably simpler, although not
necessarily any easier to debug!
The reason you're writing an MTA is not to build a replacement for sendmail, but rather to learn about how complex Internet servers are constructed. Initially, we'll start off simple with a single-threaded server that can only process one mail message at a time. It should be able to accept a mail message from a MUA, forward the message on to its destination, and then prepare to accept the next mail message. We'll fix this limitation in the next machine problem.
Your MTA must perform two general functions:
You are responsible for the following requirements:
You don't need to anything
fancy here, just copy the message to a log file and maybe print
it to standard output so you can watch it work. You don't need
to worry about multiple users on your machine, etc.
For testing, you can just just copy the message to a log file and maybe print it to standard output so you can watch it work.
Now go to your MUA and send some mail to yourself at your
VM, using the 129.10.112.* address. Then mail to a friend at
his or her MTA.
For the last task, add MX processing to your system. Your
final MTA should look at each recipient, contact that
recipient's MTA (using the MX information for the recipient's
domain), and transfer the message to it for delivery. Try this
first with an address like denali.ccs.neu.edu (for which the MX
agent is once again amber), and then for a few non-ccs
addresses. Please only send a few messages outside of CCS;
otherwise our systems folks will get some nasty phone calls from
the NU network-security folks.
% telnet smtp.ccs.neu.edu 25This opens a TCP connection to port 25 (the well-known SMTP port) on smtp.ccs.neu.edu. You should see something like:
Trying 129.10.116.58... Connected to amber-alias.ccs.neu.edu. Escape character is '^]'. 220 amber.ccs.neu.edu ESMTP Exim 4.50 Tue, 22 Jan 2008 15:26:59 -0500The first three lines are output from the telnet program. The last is the greeting sent by the MTA (In this case Exim, not Sendmail) at smtp.ccs.neu.edu. You can then identify yourself using the HELO command:
HELO foobar.comand the MTA returns
250 amber.ccs.neu.edu Hello denali.ccs.neu.edu [129.10.116.200]if denali.ccs.neu.edu happened to be the machine you're actually using. Pretty smart MTA, huh? So much for trying to fool it---at least at this stage. Read the RFC to see what SMTP requires you to do with a HELO. We can now ask it to deliver a message for us:
MAIL FROM:and it responds:
250 OKNow, we'll try sending ourselves a message:
RCPT TO:or whoever you want to send the mail to.
250 AcceptedNote that if you use an account not at ccs.neu.edu, and you're connecting from a machine outside of ccs.neu.edu, you'll get a message like:
550 5.7.1Seems ccs.neu.edu doesn't want to be bothered with handling other people's mail. By now you're probably starting to understand why sendmail is so complicated. Luckily we're going to ignore all of these details in our MTA. Now, start sending your message:... Relaying denied
DATAThe server responds
354 Enter message, ending with "." on a line by itselfNow we can send the message:
This is a sample message. It has two lines, followed by a "." on a line by itself .Note that you must end your message with a . on a line by itself. (Have we made that clear?) The server responds with:
250 OK id=1JHPp7-0000II-4ZGreat. Now we can log off.
QUIT 221 amber.ccs.neu.edu closing connection Connection to amber-alias.ccs.neu.edu closed by foreign host.If everything went well, you've now got mail! That's all there is to it.
Of course, there weren't any header lines in your message, so the message arrives from no recipient with no subject. This happened to work because amber is very tolerant about mail from denali. It won't be so tolerant about mail from your VM.
Up until now, you've always contacted a fixed MTA: either amber.ccs.neu.edu or one of the MTAs on the VMs at 129.10.112.xxx.
A real mail transfer agent would take an arbitrary recipient and contact the recipient's destination more or less directly. Unfortunately, you can't simply contact the destination directly, since not every destination runs an MTA service. In that case, you need to contact the destination's mail exchanger, which is a machine (or a set of machines) that receive mail for that destination. This information is stored in so-called MX records in the DNS.
You can see for yourself using the dig mx command:
wand@denali: ~> dig ccs.neu.edu mx ; <<>> DiG 9.2.1 <<>> ccs.neu.edu mx ;; global options: printcmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 50993 ;; flags: qr aa rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 6, ADDITIONAL: 7 ;; QUESTION SECTION: ;ccs.neu.edu. IN MX ;; ANSWER SECTION: ccs.neu.edu. 3600 IN MX 10 amber.ccs.neu.edu. ccs.neu.edu. 3600 IN MX 50 atlantis.ccs.neu.edu. ;; AUTHORITY SECTION: ccs.neu.edu. 3600 IN NS rivendell.ccs.neu.edu. ccs.neu.edu. 3600 IN NS mcs.anl.gov. ccs.neu.edu. 3600 IN NS amber.ccs.neu.edu. ccs.neu.edu. 3600 IN NS joppa.ccs.neu.edu. ccs.neu.edu. 3600 IN NS tigana.ccs.neu.edu. ccs.neu.edu. 3600 IN NS alderaan.ccs.neu.edu. ;; ADDITIONAL SECTION: amber.ccs.neu.edu. 3600 IN A 129.10.116.51 atlantis.ccs.neu.edu. 3600 IN A 129.10.116.41 mcs.anl.gov. 6180 IN A 140.221.9.6 joppa.ccs.neu.edu. 3600 IN A 129.10.116.53 tigana.ccs.neu.edu. 3600 IN A 129.10.116.83 alderaan.ccs.neu.edu. 3600 IN A 129.10.116.80 rivendell.ccs.neu.edu. 3600 IN A 129.10.116.52 ;; Query time: 1 msec ;; SERVER: 129.10.116.80#53(129.10.116.80) ;; WHEN: Thu Jan 24 07:18:51 2008 ;; MSG SIZE rcvd: 315This tells us that ccs.neu.edu uses two mail servers: amber.ccs.neu.edu and atlantis.ccs.neu.edu, so mail to somebody at ccs.neu.edu should typically be sent to amber.ccs.neu.edu.
As you can see, MX processing is a complicated business, and we don't intend for you to build one yourself. There are programs available for MX processing in several languages-- go find one and use it. (And tell us where you found it, as you did in MP1.) If you really, really want to use C, Alex Snoeren, from whom I got this problem, has provided some files for doing this.
Your deliverables should include a description of your program and its parts, and a description of what header processing (and other processing) you do.
Attribution: If you got portions of your program from external libraries (on the internet or wherever), tell us what they are and where you got them. Otherwise we will assume that you wrote every line yourself, and nasty things will happen if that turns out to be false.
Submit your package as a gzipped tar file. You can build this by doing something like
mkdir mp2 cp {all files} mp2 tar cvf mp2.tar mp2 gzip mp2.tar mv mp2.tar.gz yourname-mp2.tar.gzSend yourname-mp2.tar.gz to xindong@ccs.neu.edu.