Advertisement
Guest User

Untitled

a guest
Feb 6th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. from socket import *
  2.  
  3. # Message to send
  4. msg = b"\r\n I love computer networks!"
  5. endmsg = b"\r\n.\r\n"
  6.  
  7. # Our mail server is smtp.stud.ntnu.no
  8. mailserver = 'smtp.stud.ntnu.no'
  9.  
  10. # Create socket called clientSocket and establish a TCP connection
  11. # (use the appropriate port) with mailserver
  12. #Fill in start
  13.  
  14. serverPort = 25
  15. clientSocket = socket(AF_INET, SOCK_STREAM)
  16. clientSocket.connect((mailserver, serverPort))
  17.  
  18. #Fill in end
  19.  
  20. recv = clientSocket.recv(1024)
  21. print(recv)
  22. if recv[:3] != b'220':
  23. print('220 reply not received from server.')
  24.  
  25. # Send HELO command and print server response.
  26. heloCommand = b'HELO Alice\r\n'
  27. clientSocket.send(heloCommand)
  28. recv1 = clientSocket.recv(1024)
  29. print(recv1)
  30. if recv1[:3] != b'250':
  31. print('250 reply not received from server.')
  32.  
  33. # Send MAIL FROM command and print server response.
  34. # Fill in start
  35.  
  36. mailfromCommand = b'MAIL FROM: <frommail@gmail.com>\r\n'
  37. clientSocket.send(mailfromCommand)
  38. recv2 = clientSocket.recv(1024)
  39. print(recv2)
  40.  
  41. # Fill in end
  42.  
  43. # Send RCPT TO command and print server response.
  44. # Fill in start
  45.  
  46. rcpttoCommand = b'RCPT TO:<tomail@gmail.no>\r\n'
  47. clientSocket.send(rcpttoCommand)
  48. recv3 = clientSocket.recv(1024)
  49. print(recv3)
  50.  
  51. # Fill in end
  52.  
  53. # Send DATA command and print server response.
  54. # Fill in start
  55.  
  56. dataCommand = b'DATA\r\n'
  57. clientSocket.send(dataCommand)
  58. recv4 = clientSocket.recv(1024)
  59. print(recv4)
  60.  
  61. # Fill in end
  62.  
  63. # Send message data.
  64. # Fill in start
  65.  
  66. messagedataCommand = msg
  67. clientSocket.send(messagedataCommand)
  68.  
  69. # Fill in end
  70.  
  71. # Message ends with a single period.
  72. # Fill in start
  73.  
  74. endswithsingleperiodCommand = endmsg
  75. clientSocket.send(endswithsingleperiodCommand)
  76. recv6 = clientSocket.recv(1024)
  77. print(recv6)
  78.  
  79. # Fill in end
  80.  
  81. # Send QUIT command and get server response.
  82. # Fill in start
  83.  
  84. quitCommand = b'QUIT\r\n'
  85. clientSocket.send(quitCommand)
  86. recv7 = clientSocket.recv(1024)
  87. print(recv7)
  88.  
  89. # Fill in end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement