Question

Skeleton Python Code for the Mail Client from socket import * msg =”\r\n I love computer...

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

Homework Answers

Answer #1

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

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
The code I have written runs but I need it us UDP not TCP. Also I...
The code I have written runs but I need it us UDP not TCP. Also I just need someone to check my work and make sure that it works properly. The python code needs to be run with command line so you can add more than one client. The directions: 1. The chat is performed between 2 clients and not the server. 2. The server will first start up and choose a port number. Then the server prints out its...
currently the code contacts the server 1 time and exits. Modify the code so that the...
currently the code contacts the server 1 time and exits. Modify the code so that the program contacts the server five times before exiting. /* client.c - code for example client program that uses TCP */ #ifndef unix #define WIN32 #include <windows.h> #include <winsock.h> #else #define closesocket close #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <netdb.h> #endif #include <stdio.h> #include <string.h> #include <stdlib.h> #include <unistd.h> #define PROTOPORT 5193 /* default protocol port number */ extern int errno; char...
1. Please use only the C as the language of programming. 2. Please submit/upload on Canvas,...
1. Please use only the C as the language of programming. 2. Please submit/upload on Canvas, the following les for each of your programs: (1) the client and the server source les each (2) the client and the serve executable les each (3) a brief Readme le that shows the usage of the program. 3. Please appropriately comment your program and name all the identiers suitable, to enable enhanced readability of the code. Problems 1. Write an ftp client that...
please can you make it simple. For example using scanner or hard coding when it is...
please can you make it simple. For example using scanner or hard coding when it is a good idea instead of arrays and that stuff.Please just make one program (or class) and explain step by step. Also it was given to me a txt.htm 1.- Write a client program and a server program to implement the following simplified HTTP protocol based on TCP service. Please make sure your program supports multiple clients. The webpage file CS3700.htm is provided. You may...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT