Advertisement
Guest User

Untitled

a guest
Nov 30th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.11 KB | None | 0 0
  1. #!/usr/bin/python
  2. default_encoding = 'utf-8'
  3. import socket
  4. import ssl
  5. import base64
  6. import time
  7.  
  8.  
  9.  
  10. context = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
  11. context.verify_mode = ssl.CERT_REQUIRED
  12. context.check_hostname = True
  13. context.load_default_certs()
  14. msg = "\r\n I love computer networks!"
  15. endmsg = "\r\n.\r\n"
  16.  
  17. mailserver = ('smtp.cc.ncu.edu.tw', 587)
  18.  
  19. clientSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  20.  
  21. ssl_sock = context.wrap_socket(clientSocket, server_hostname = 'smtp.cc.ncu.edu.tw')
  22.  
  23. clientSocket.connect(mailserver)
  24.  
  25. recv = clientSocket.recv(1024).decode()
  26.  
  27. print(recv)
  28. if recv[:3] != '220':
  29. print('220 reply not received from server.')
  30.  
  31. heloCommand = 'HELO Alice\r\n'
  32. clientSocket.send(heloCommand.encode())
  33.  
  34. recv1 = clientSocket.recv(1024).decode()
  35.  
  36. print(recv1)
  37. if recv1[:3] != '250':
  38. print('250 reply not received from server.')
  39.  
  40. username = "" #YourEmailAddress
  41. password = "" #YourEmailPassword
  42.  
  43. base64_usernameAndPassword = ("\x00" + username + "\x00" + password).encode()
  44. base64_usernameAndPassword = base64.b64encode(base64_usernameAndPassword)
  45.  
  46. authMsg = "AUTH PLAIN ".encode() + base64_usernameAndPassword + "\r\n".encode()
  47. clientSocket.send(authMsg)
  48.  
  49. recv_auth = clientSocket.recv(1024)
  50.  
  51. print(recv_auth.decode())
  52.  
  53. mailFrom = "MAIL FROM: <>\r\n" #YourEmailAddress(SEND)
  54. clientSocket.send(mailFrom.encode())
  55. recv = clientSocket.recv(1024).decode()
  56. print("MAIL FROM after: "+recv)
  57.  
  58. rcptTo = "RCPT TO:<>\r\n" #YourEmailAddress(RCV)
  59. clientSocket.send(rcptTo.encode())
  60. recv = clientSocket.recv(1024).decode()
  61. print("MAIL FROM after: "+ recv)
  62.  
  63. data = "DATA\r\n"
  64. clientSocket.send(data.encode())
  65. recv = clientSocket.recv(1024).decode()
  66. print("DATA after: " + recv)
  67.  
  68. Subject = "Subject: blyat\r\n"
  69. clientSocket.send(Subject.encode())
  70.  
  71. clientSocket.send(msg.encode())
  72. clientSocket.send("\r\n".encode())
  73. clientSocket.send(endmsg.encode())
  74. recv = clientSocket.recv(1024).decode()
  75. print("after send message:" + recv)
  76.  
  77. quit = "QUIT\r\n"
  78. clientSocket.send(quit.encode())
  79. recv = clientSocket.recv(1024).decode()
  80. print(recv)
  81.  
  82. clientSocket.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement