This document contains code for an SMTP client program with comments describing its purpose, author, and creation date. It connects to a mail server, sends HELLO, MAIL FROM, and RCPT TO commands, and prints the server responses to validate the commands were accepted. The client is designed to send a simple message from one email address to another.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
32 views2 pages
SMTP
This document contains code for an SMTP client program with comments describing its purpose, author, and creation date. It connects to a mail server, sends HELLO, MAIL FROM, and RCPT TO commands, and prints the server responses to validate the commands were accepted. The client is designed to send a simple message from one email address to another.
• 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 = 'localhost' • mailPort = 7890 # Create socket caLLed cLientSocket and estabLish a TCP connection with maiLser SMTPClientSocket = socket(AF_INET, SOCK_STREAM) SMTPClientSocket.connect((mailServer, mailPort)) recv = clientSocket.recv(1024) print recv if recv[:3] != '220': print '220 reply not received from server.' # Send HELLO command and print server response. helloCommand = 'HELLO Alice\r\n' clientSocket.send(helloCommand) recvl = clientSocket.recv(1024) print recvl if recvl[:3] I= '250': print '250 reply not received from server.' # Send MAIL FROM command and print server response. mailfromCommand = '<[email protected]>\r\n' SMTPClientSocket.send(mailfromCommand) recvl = clientSocket.recv(1024) print recvl if recvl[:3] != '250': print '250 reply not received from server.' # Send RCPT TO command and print server response. rcpttoCommand = '<[email protected]>\r\n' SMTPClientSocket.send(rcpttoCommand)