Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Help please in python from socket import * import 331 import base 64 # Message to send msg = ' Hey There! Im sending this

image text in transcribedimage text in transcribed

Help please in python

from socket import * import 331 import base 64 # Message to send msg = ' Hey There! Im sending this email from Python via Sockets!' endmsg = ' ' # Choose a mail server (e.g. Google mail server) and call it mailserver mailserver = 'smtp.gmail.com' or 'smtp.office365.com' for outlook e.g. SBU mail server # TO DO:Create socket called client Socket and establish a TCP connection with mailserver # Connect to the mail server through the Port number may change according to the mail server. SMTP Default is 587 for gmail and outlook for use by mail clients client Socket.connect((mailserver, 587)) #Receive the response through the socket and decode it conResponse = client Socket.recv(1024).decode() # To Do:Print the received information # WHAT IS THE MEANING OF SMTP STATUS CODE 220? if conResponse[:3] != '220': print('220 reply not received from server.') # Send HELO command and print server response. helloCommand = 'HELO gmail.com ' #To Do: Send your encoded hello command via your socket #Receive the response through the socket and decode it helloResponse = client Socket.recv(1024).decode() #To Do:Print the received information #WHAT DOES THE STARTTLS COMMAND Do? client Socket.send('STARTTLS '.encode()) tlsResponse = client Socket.recv(1024).decode() print (tls Response) #Wrap the socket around a secure TLS connection context = 331.create_default_context() context = 331. SSLContext (331. PROTOCOL_TLS) client Socket = context.wrap_socket (client Socket) #Send an authentication command to login to mail server client Socket.send('AUTH LOGIN '.encode()) loginResponse = client Socket.recv(1024).decode() print (loginResponse) #If command was successful the server responds with a status code and message (334 VXNlcm5hbWU6) #WHAT IS THE MEANING OF THE ABOVE STATUS CODE AND MESSAGE? #Another status code and message is also displayed (334 UGFzc3dvcmQ6) #WHAT IS THE MEANING OF THE ABOVE STATUS CODE AND MESSE #Send the base64 eoncoded login credentials to the mail server # To Do: Replace 'your_user_name' with your actual email user client Socket.send (base64.b64encode(('your_user_name').encode())) client Socket.send(' ').encode()) # To Do: Replace 'your_password' with your actual email Password client Socket.send (base64.b64encode(('your_password').encode())) client Socket.send((' ').encode()) # Send MAIL FROM command and print server response. # To Do: Replaced 'your_gmail_address with your actual Gmail address mailfrom = 'MAIL FROM: ' client Socket.send (mailfrom.encode()) mailFromResponse = client Socket.recv(1024).decode() #To Do: Print the received information #WHAT IS THE STATUS CODE & MESSAGE AND WHAT DO THEY MEAN? # Send RCPT TO command and print server response. rcptto = 'RCPT TO: ' client Socket.send (rcptto.encode()) rcptResponse = client Socket.recv (1024).decode() #To Do: Print the received information #WHAT IS THE STATUS CODE & MESSAGE AND WHAT DO THEY MEAN? # Send DATA command and print server response. data = DATA ' #To Do: Send the encoded data' via the client socket #Receive the information from server dataResponse = client Socket.recv (1024).decode() #To Do: Print the received information #WHAT IS THE STATUS CODE & MESSAGE AND WHAT DO THEY MEAN? # Send message data. client Socket.send('SUBJECT: Greetings to you! '.encode()) client Socket.send('test again'.encode()) client Socket.send (msg.encode()) # Message ends with a single period. client Socket.send(endmsg.encode()) endResponse = client Socket.recv(1024).decode() print (endResponse) if endResponse[:3] != '250': print('250 reply not received from server.') # Send QUIT command and get server response. quit command = "QUIT client Socket.send (quitcommand.encode()) quitResponse = client Socket.recv(1024).decode() print (quitResponse) if quitResponse[:3] != '221': print('221 reply not received from server.')

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions