Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from socket import *
- # Message to send
- msg = b"\r\n I love computer networks!"
- endmsg = b"\r\n.\r\n"
- # Our mail server is smtp.stud.ntnu.no
- mailserver = 'smtp.stud.ntnu.no'
- # Create socket called clientSocket and establish a TCP connection
- # (use the appropriate port) with mailserver
- #Fill in start
- serverPort = 25
- clientSocket = socket(AF_INET, SOCK_STREAM)
- clientSocket.connect((mailserver, serverPort))
- #Fill in end
- recv = clientSocket.recv(1024)
- print(recv)
- if recv[:3] != b'220':
- print('220 reply not received from server.')
- # Send HELO command and print server response.
- heloCommand = b'HELO Alice\r\n'
- clientSocket.send(heloCommand)
- recv1 = clientSocket.recv(1024)
- print(recv1)
- if recv1[:3] != b'250':
- print('250 reply not received from server.')
- # Send MAIL FROM command and print server response.
- # Fill in start
- mailfromCommand = b'MAIL FROM: <frommail@gmail.com>\r\n'
- clientSocket.send(mailfromCommand)
- recv2 = clientSocket.recv(1024)
- print(recv2)
- # Fill in end
- # Send RCPT TO command and print server response.
- # Fill in start
- rcpttoCommand = b'RCPT TO:<tomail@gmail.no>\r\n'
- clientSocket.send(rcpttoCommand)
- recv3 = clientSocket.recv(1024)
- print(recv3)
- # Fill in end
- # Send DATA command and print server response.
- # Fill in start
- dataCommand = b'DATA\r\n'
- clientSocket.send(dataCommand)
- recv4 = clientSocket.recv(1024)
- print(recv4)
- # Fill in end
- # Send message data.
- # Fill in start
- messagedataCommand = msg
- clientSocket.send(messagedataCommand)
- # Fill in end
- # Message ends with a single period.
- # Fill in start
- endswithsingleperiodCommand = endmsg
- clientSocket.send(endswithsingleperiodCommand)
- recv6 = clientSocket.recv(1024)
- print(recv6)
- # Fill in end
- # Send QUIT command and get server response.
- # Fill in start
- quitCommand = b'QUIT\r\n'
- clientSocket.send(quitCommand)
- recv7 = clientSocket.recv(1024)
- print(recv7)
- # Fill in end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement