The Email Client

Your task is to write an email client.  It should be able to connect to an email server, and deliver email to that server.  You must use the SMTP protocol.
 
 

Points

Task

10

Makes a socket to the email server

10

Gets the username and email server name from the user

10

Gets the body of the message from the user

10

Can figure out the MX server programatically (Extra Credit. Very hard. Most people don’t get this!)

60

User actually gets email

10

Prints an informative error message if the user does not exist

-5

Every error check missing from read or write

-10

Each day after Fri Feb 23th

Here's a sample dialog between a user and the program
 

Send to whom?> randy 
At what SMTP Server?> euclid.nmu.edu 
From what person?> god@heaven.org 
Enter the message.  End that message with a '.' on a line by itself. 
Give me an 'A' or you will burn in the eternal fires of CS120 forever!!!! 

Message Sent 
bash# 

Here is the SMTP dialog.

220 mx.google.com ESMTP p19-20020a5d9853000000b007c7432a1405si101698ios.20 - gsmtp
HELO whitehouse.gov
250 mx.google.com at your service
MAIL FROM:<jbiden@whitehouse.gov>
250 2.1.0 OK t18-20020a05620a451200b00785d1447e6bsi10188272qkp.757 – gsmtp
RCPT TO:<kitplane01@gmail.com>
250 2.1.5 OK t18-20020a05620a451200b00785d1447e6bsi10188272qkp.757 – gsmtp
DATA
354 Go ahead t18-20020a05620a451200b00785d1447e6bsi10188272qkp.757 – gsmtp
Date:Wed, 14 Feb 2024 9:22:00
Message-ID:<CAEb5kgpPWSWWqL0Kj=Nui2NbTcF+_tB6CKXfAQzdZBpK6wzp=w@mail.gmail.com>
Subject: Vote for me
To: kitplane01@gmail.com
From: jbiden@whitehouse.gov

Vote for me
Me!
.

250 2.0.0 OK 1707943177 t18-20020a05620a451200b00785d1447e6bsi10188272qkp.757 – gsmtp
QUIT
221 2.0.0 closing connection t18-20020a05620a451200b00785d1447e6bsi10188272qkp.757 - gsmtp



Checklist:

  1. connect to the server

  2. Read from the server. If they don't reply, you're blocked!

  3. send "HELO sourcehostname\r\n"

  4. check for a good reply

  5. send "MAIL FROM:\r\n"

  6. check for a good reply

  7. send "RCPT TO:\r\n"

  8. Check for a good reply

  9. Send "DATA\r\n"

  10. Check for a good reply

  11. Send "To:destusername@destsourcename\r\n"

  12. Send "From: sourceusername@sourcehostname\r\n"

  13. Send "Message-ID: \r\n"

  14. Send "Subject: thesubject\r\n"

  15. Send "Date: thedate\r\n"

  16. Send "\r\n"

  17. Send the text of the message and then "\r\n"

  18. Send ".\r\n"

  19. Check for a good reply

  20. Send "QUIT\r\n"

  21. Check for a good reply

  22. exit the program.

  23. Go check you email. It PROBABLY in your spam folder