CSc 423 Assignment 2

Mail Help

Assigned
Due

Jan 31
45 pts
Feb 12
This assignment shold provide some more experience with Cleansocks, and chance to actually interact with a server. We will write a small program which will connect to an SMTP server, run the HELP command (which generates a small amount of text), then quit. We will be following the standard protocol given in RFC 5321. In the process the program should log the interaction with the server. Mine looks like this:
user@home$ ./smhelp0 smtp.gmail.com S: 220 smtp.gmail.com ESMTP p13-20020a4ad44d000000b005990bd1e1dcsm2191153oos.17 - gsmtp C: EHLO 192.168.1.136 S: 250-smtp.gmail.com at your service, [76.107.18.246] S: 250-SIZE 35882577 S: 250-8BITMIME S: 250-STARTTLS S: 250-ENHANCEDSTATUSCODES S: 250-PIPELINING S: 250-CHUNKING S: 250 SMTPUTF8 C: HELP S: 214 2.0.0 https://www.google.com/search?btnI&q=RFC+5321 p13-20020a4ad44d000000b005990bd1e1dcsm2191153oos.17 - gsmtp C: QUIT S: 221 2.0.0 closing connection p13-20020a4ad44d000000b005990bd1e1dcsm2191153oos.17 - gsmtp

SMTP is a classic line-oriented protocol. The output above shows the program's interaction with the specified server. Lines starting with S: were sent by the server to us, and lines starting with C: were sent by us to the server. Each line is terminated with \r\n, though not displayed on the output. Each line sent by the client starts with a four-letter command. Each response from the server starts with a three-digit code. Responses may be one line or several. Multi-line responses have a - after the number for all lines but the last, as you can see above. Any response may be single- or multi-line. The three-digit code is a bit like the HTTP response codes: the first digit gives the class of the response. The 200s are successes, and 500s are the permanent errors. See RFC 5321 for details.

Your program should do the following:
  1. Accept on the command line a host name and an optional port number. If no port is provided, look up the port number for the service msa (which is 587).
  2. Connect to the host on the indicated port.
  3. The server should respond to your connection with a 220 success method (or possibly an error). Read and print that.
  4. Send the server the EHLO message, with your IP address, as shown. Echo it before you send it.
  5. The server should respond with a 250, usually a multi-line message that lists the features of the server. Read and print the message.
  6. Send the HELP command, just that one word, as shown. Also echo it.
  7. Receive and print the response.
  8. Send and echo the QUIT command.
  9. Read and echo the response, then close the connection.

Notes

  1. You will find this a lot easier if you use a Cleansocks buffered socket so you can use the readln method to read a line at a time. The chat example shows its use.
  2. Any server response might be multi-line. This will require a loop on a recvln. You might want to put it in a function so you can call it from any place it is needed.
  3. When echoing messages, you should avoid printing the \r\n to the console.
  4. I also made a function to echo and send a message to the server. It's only two lines, but worth the small bit of trouble.
  5. If any server response is an error (5xx code), immediately send QUIT and close the connection. This will probably not happen, except...
  6. Though the RFC 5321 specifies a HELP command, some servers do not recognize it. (It is a bit of an anachronism, and no one enforces RFCs after all.) You might get an error for that.
  7. The standard SMTP port is 25, but convention now is to use 25 when mail is transferred from one SMTP server to another. The 587 msa port is used when a client makes an initial mail transmission to a server, so they're more likely to talk to you on that port. Either runs the same SMTP protocol, and your program should work fine on port 25 smtp, if you find a server that will accept your connection.
  8. Some servers I have been able to connect to are smtp.comcast.net, smtp.gmail.com, smtp-mail.outlook.com and mail.mailinator.com. The last one returns an error for the HELP command. There are no doubt many you can use.

Submission

When your program is working, nicely commented and properly indented, submit it using the form here