CS2910
Lab 6

This is an old version of this course, from Fall 2015. A newer version is available here.

Lab Assignment

This is a team assignment; each team should be two members unless a different size is approved by the instructor.

Installing pytz

Download the template. Start PyCharm as an administrator. In Pycharm, find the pytz import, which will be underlined in red. Press Alt-Enter on the underlined term. Choose to install the package. Restart PyCharm, not as an administrator

If that does not work, please consult your instructor.

To the Fall 2016 offering, from the students of the Fall 2014 and 2015 offerings of this class: The wireless in the dorms is reported to block the port needed to send email using SMTP. However, the wireless in the lobby of the dorms might work. So leave the time to go to the CC for testing, if needed. Sorry!

Introduction

The goal of this lab is to write a short Python program, to send an email message to an email server, using the SMTP protocol, STARTTLS security, and AUTH LOGIN authentication.

Procedure

  1. Download the skeleton Python template: smtp.py
  2. Edit the header of the file to include your team members' names, in the format provided.
  3. Complete the smtp_send method to send an email message with at least the following content:
    • Email header
      • From
      • To (one recipient; optionally, you may add more by using a list of strings for this value)
      • Subject
      • Date
    • Email text (may be multiple lines)
    Optionally, you may add other capabilities, such as sending an attachment, but make sure that all the required functionality is completely working first.

    You will want to add other helper methods, or other named constants, but do not change any other code provided in the template.
  4. Add comments at the end of your Python file, with the following information:
    • A description of the functionality you implemented and the results of your testing.
    • Comments on your experience in completing the lab, including any problems you overcame. Briefly explain what you learned.
    • Questions and suggestions.

You may not use a prebuilt library like Lib/smtplib; the point of this lab is for you to understand the low-level implementation of the SMTP protocol.

If this base functionality turns out to be too easy, you may experiment with adding additional functions, but be sure the basic requirements are still met. Make sure you always have a working backup copy before adding features.

Begin with design, and divide up the primary responsibility for parts of the program in an equitable way.

Hints and Notes

  1. As in the HTTP labs, you will have to both send and receive on the TCP connection to the SMTP client. By now, you should probably have a "read line" function, and it may be helpful to have a function that can send an SMTP command and return the response (status code and accompanying data) in a form that is easy to search for a particular response line's "value".
  2. By now, you should know how to read from a network stream; if you still have questions, ask the instructor for assistance.
  3. Getting the proper SMTP "Date" value can be a little tricky. For now, just use the provided get_formatted_date() function.
  4. To convert a non-secure TCP connection into an SSL/TLS secure connection, you can "wrap" the existing TCP socket: skt = ssl.wrap_socket(skt_nonssl, ssl_version=ssl.PROTOCOL_SSLv3) In this example, after wrapping the original skt_nonssl socket, you would switch over to using the skt socket for the subsequent secure operations. For more information, including different protocol versions (which may be needed for some SMTP servers), see docs.python.org/2/library/ssl.html. The available protocols vary by Python version; for Python 2.7.9, the available options are:
    • PROTOCOL_SSLv2
    • PROTOCOL_SSLv23 (This is the default, and it is a good one.)
    • PROTOCOL_SSLv3
    • PROTOCOL_TLSv1
    • PROTOCOL_TLSv1_1
    • PROTOCOL_TLSv1_2
    You can see which protocol versions are available by typing the following command in an interactive Python window:
    >>> import ssl
    >>> dir (ssl)	
    
    Look for the symbols that start with "PROTOCOL_".
  5. You can find documentation of email header elements in RFC 5322, titled Internet Message Format.
  6. When you have questions you can't resolve, consult the instructor as soon as possible, in person or by email.

Submission

Please submit your file below. Please make sure your usernames are separated by hyphens and in alphabetical order.

(Acknowledgements: The original version of this lab written by Dr. Sebern.)