By the end of this lab, you will have acquired a better understanding of SMTP protocol. You will also gain experience in implementing a standard protocol using Python. Your task is to develop a simple mail client that sends email to any recipient. Your client will need to connect to a mail server, dialogue with the mail server using the SMTP protocol, and send an email message to the mail server. Python provides a module, called smtplib, which has built-in methods to send mail using SMTP protocol. However, you will not be using this module in this lab, because it hides the details of SMTP and socket programming.    In order to limit spam, some mail servers do not accept TCP connections from arbitrary sources. For the experiment described below, you may want to try connecting both to your university mail server and to a popular Webmail server, such as an AOL mail server. To connect to the university mail server, you will need to use NYU’s VPN. You may also try making your connection both from your home and from your university campus. from socket import * def smtp_client(port=1025, mailserver='127.0.0.1'): msg = "\r\n My message" endmsg = "\r\n.\r\n"

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

By the end of this lab, you will have acquired a better understanding of SMTP protocol. You will also gain experience in implementing a standard protocol using Python.

Your task is to develop a simple mail client that sends email to any recipient. Your client will need to connect to a mail server, dialogue with the mail server using the SMTP protocol, and send an email message to the mail server. Python provides a module, called smtplib, which has built-in methods to send mail using SMTP protocol. However, you will not be using this module in this lab, because it hides the details of SMTP and socket programming. 

 

In order to limit spam, some mail servers do not accept TCP connections from arbitrary sources. For the experiment described below, you may want to try connecting both to your university mail server and to a popular Webmail server, such as an AOL mail server. To connect to the university mail server, you will need to use NYU’s VPN. You may also try making your connection both from your home and from your university campus.


from socket import *


def smtp_client(port=1025, mailserver='127.0.0.1'):
msg = "\r\n My message"
endmsg = "\r\n.\r\n"

# Choose a mail server (e.g. Google mail server) if you want to verify the script beyond GradeScope

# Create socket called clientSocket and establish a TCP connection with mailserver and port
clientSocket = socket(AF_INET, SOCK_STREAM)
clientSocket.connect((mailserver, port))
# Fill in start
# Fill in end

recv = clientSocket.recv(1024).decode()
print(recv)
if recv[:3] != '220':
print('220 reply not received from server.')

# Send HELO command and print server response.
heloCommand = 'HELO Alice\r\n'
clientSocket.send(heloCommand.encode())
recv1 = clientSocket.recv(1024).decode()
# print(recv1)
if recv1[:3] != '250':
print('250 reply not received from server.')

# Send MAIL FROM command and print server response.
# Fill in start
mailFrom = 'Mail from<xugeegeegee@gmail.com>\r\n'
clientSocket.send(mailFrom.encode())
recv1 = clientSocket.recv(1024).decode()
# print(recv1)
if recv1[:3] != '250':
print('250 reply not received from server.')
# Fill in end

# Send RCPT TO command and print server response.
# Fill in start
rcptTo = 'RCPT TO: <smtp.nyu.edu> \r\n'
clientSocket.send(rcptTo.encode())
recv1 = clientSocket.recv(1024)
# print("After RCPT TO command: " + recv3)
if recv1[:3] != '250':
print('250 reply not received from server.')

# Fill in end

# Send DATA command and print server response.
# Fill in start
data = 'DATA\r\n'
clientSocket.send(data.encode())
recv1 = clientSocket.recv(1024)
# print("After DATA command: " + recv4)
if recv1[:3] != '250':
print('250 reply not received from server.')

# Fill in end

# Send message data.
# Fill in start
clientSocket.send('\r\n')
clientSocket.send(msg)
clientSocket.send(endmsg)
# Fill in end

# Message ends with a single period.
# Fill in start
clientSocket.send('.\r\n')
recv1 = clientSocket.recv(1024)
print(recv1)
if recv1[:3] != '250':
print('250 reply not received from server.')
# Fill in end

# Send QUIT command and get server response.
# Fill in start
quit = 'QUIT\r\n'
clientSocket.send(quit.encode())
recv1 = clientSocket.recv(1024)
# print(recv1)
if recv1[:3] != '250':
print('250 reply not received from server.')
clientSocket.close()
# Fill in end


if __name__ == '__main__':
smtp_client(1025, '127.0.0.1')

This is my code, can you help me find where did I do wrong?

from socket import *
def smtp client (port=1025, mailserver='127.0.0.1'):
msg = "\r\n My message"
endmsg
"\r\n.\r\n"
# Choose a mail server (e.g. Google mail server)
if you want to verify the script beyond GradeScope
# Create socket called clientSocket and establish a TCP connection with mailserver and port
# Fill in start
# Fill in end
recv = clientSocket.recv(1024).decode ()
print (recv)
if recv[:3]
print ('220 reply not received from server.')
!= '220':
# Send HELO command and print server response.
heloCommand
'HELO Alice\r\n'
clientSocket.send (heloCommand.encode () )
recv1 = clientSocket.recv(1024).decode ()
print (recv1)
if recvl[:3] != '250':
print ('250 reply not received from server.')
# Send MAIL FROM command and print server response.
# Fill in start
# Fill in end
# Send RCPT TO command and print server response.
# Fill in start
# Fill in end
# Send DATA command and print server response.
# Fill in start
# Fill in end
# Send message data.
# Fill in start
# Fill in end
# Message ends with a single period.
# Fill in start
# Fill in end
# Send QUIT command and get server response.
# Fill in start
# Fill in end
if
name
main
smtp_client (1025, '127.0.0.1')
Transcribed Image Text:from socket import * def smtp client (port=1025, mailserver='127.0.0.1'): msg = "\r\n My message" endmsg "\r\n.\r\n" # Choose a mail server (e.g. Google mail server) if you want to verify the script beyond GradeScope # Create socket called clientSocket and establish a TCP connection with mailserver and port # Fill in start # Fill in end recv = clientSocket.recv(1024).decode () print (recv) if recv[:3] print ('220 reply not received from server.') != '220': # Send HELO command and print server response. heloCommand 'HELO Alice\r\n' clientSocket.send (heloCommand.encode () ) recv1 = clientSocket.recv(1024).decode () print (recv1) if recvl[:3] != '250': print ('250 reply not received from server.') # Send MAIL FROM command and print server response. # Fill in start # Fill in end # Send RCPT TO command and print server response. # Fill in start # Fill in end # Send DATA command and print server response. # Fill in start # Fill in end # Send message data. # Fill in start # Fill in end # Message ends with a single period. # Fill in start # Fill in end # Send QUIT command and get server response. # Fill in start # Fill in end if name main smtp_client (1025, '127.0.0.1')
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Random Class and its operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education