Skeleton Python Code for the Mail Client
from socket import *
msg =”\r\n I love computer networks!”
endmsg = ”\r\n.\r\n”
# Choose a mail server (e.g. Google mail server) and call it mailserver
mailserver = #Fill in start #Fill in end
# Create socket called clientSocket and establish a TCP connection with mailserver
#Fill in start
#Fill in end
recv = clientSocket.recv(1024)
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) recv1 = clientSocket.recv(1024)
print recv1
if recv1[: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
1. Mail servers like Google mail (address: smtp.g mail.com, port: 587) requires your client to add a Transport Layer Security (TLS) or Secure Sockets Layer (SSL) for authentication and security reasons, before you send MAIL FROM command. Add TLS/SSL commands to your existing ones and implement your client using Google mail server at above address and port
Code:
#serverAddress: address of serverAddress. I have set it to "localhost", you can change it suit your needs.
#portNumber: portNumber on which software is running
#sendersEmailAddress: email address from which email is sent.
#receiversEmailAddress: email address to which email is ent
from socket import *
msg = "\r\n I love computer networks!"
endmsg = "\r\n.\r\n"
serverAddress = "localhost"
portNumber = 25
sendersEmailAddress = "[email protected]"
receiversEmailAddress = "[email protected]"
# Connect to the local host (an EECS serverAddress, where this code should be executed)
mailServer = (serverAddress, portNumber)
# Create socket called clientSocket and establish a TCP connection with nailserverAddress
#Fill in start
clientSocket = socket(AF_INET, SOCK_STREAM)
clientSocket.connect(mailServer)
#Fill in end
recv = clientSocket.recv(1024).decode()
print(recv)
if recv[:3] != '220':
print('220 reply not received from serverAddress.')
# Send HELO command and print serverAddress 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 serverAddress.')
# Send MAIL FROM command and print serverAddress response.
# Fill in start
fromCommand = 'MAIL FROM: ' + sendersEmailAddress + '\r\n'
clientSocket.send(fromCommand.encode())
recv2 = clientSocket.recv(1024).decode()
print(recv2)
# Fill in end
# Send RCPT TO command and print serverAddress response.
# Fill in start
rcptCommand = 'RCPT TO: ' + receiversEmailAddress + '\r\n'
clientSocket.send(rcptCommand.encode())
recv3 = clientSocket.recv(1024).decode()
print(recv3)
# Fill in end
# Send DATA command and print serverAddress response.
# Fill in start
dataCommand = 'DATA\r\n'
clientSocket.send(dataCommand.encode())
recv4 = clientSocket.recv(1024).decode()
print(recv4)
# Fill in end
# Send message data.
# Fill in start
clientSocket.send(msg.encode())
# Fill in end
# Message ends with a single period.
# Fill in start
clientSocket.send(endmsg.encode())
recv5 = clientSocket.recv(1024).decode()
print(recv5)
# Fill in end
# Send QUIT command and get serverAddress response.
# Fill in start
quitCommand = 'QUIT\r\n'
clientSocket.send(quitCommand.encode())
recv6 = clientSocket.recv(1024).decode()
print(recv6)
# Fill in end
M #serverAddress: address of serverAddress. I have set it to "localhost", you can change it suit your needs. #portNumber: portNumber on which software is running #sendersEmailAddress: email address from which email is sent. #receivers EmailAddress: email address to which email is ent from socket import Number * OOOI msg = "\r\n I love computer networks!" endmsg = "\r\n\r\n" serverAddress = "localhost" portNumber = 25 senders EmailAddress = "[email protected]" receivers EmailAddress = "[email protected]" # Connect to the local host (an EECS serverAddress, where this code should be executed) mailServer = (serverAddress, portNumber) # Create socket called client Socket and establish a TCP connection with nailserverAddress #Fill in start client Socket = socket (AF INET, SOCK STREAM) client Socket.connect (mailServer) #Fill in end recv = client Socket.recv (1024).decode() print (recv) if recy[:3] != '220': print('220 reply not received from serverAddress.') # Send HELO command and print serverAddress response. heloCommand = 'HELO Alice\r\n' client Socket.send (heloCommand.encode()) recvl = client Socket.recv (1024).decode() print (recvl) if recvl[:3] != "250": print('250 reply not received from serverAddress.') # Send MAIL FROM command and print serverAddress response. # Fill in start fromCommand = 'MAIL FROM: ' + senders EmailAddress + '\r\n' client Socket.send (fromCommand.encode()) recv2 = client Socket.recv (1024).decode() print (recv2) # Fill in end 43 # Send RCPT TO command and print serverAddress response. # Fill in start rcpt Command = 'RCPT TO: ' + receivers EmailAddress + '\r\n' client Socket.send (rcptCommand.encode()) recv3 = client Socket.recv (1024).decode() print (recv3) # Fill in end # Send DATA command and print serverAddress response. # Fill in start dataCommand = 'DATA\r\n' client Socket.send (dataCommand.encode()) recv4 = client Socket.recv (1024).decode() print (recv4) # Fill in end # Send message data. # Fill in start client Socket.send (msg.encode()) # Fill in end 64 # Message ends with a single period. # Fill in start client Socket.send (endmsg.encode()) recv5 = client Socket.recv (1024).decode() print (recv5) # Fill in end # Send QUIT command and get serverAddress response. # Fill in start quitCommand = 'QUIT\r\n' client Socket.send (quitCommand.encode()) recv6 = client Socket.recv (1024).decode() print (recv6) # Fill in end
Get Answers For Free
Most questions answered within 1 hours.