Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- default_encoding = 'utf-8'
- import socket
- import ssl
- import base64
- import time
- context = ssl.SSLContext(ssl.PROTOCOL_TLSv1)
- context.verify_mode = ssl.CERT_REQUIRED
- context.check_hostname = True
- context.load_default_certs()
- msg = "\r\n I love computer networks!"
- endmsg = "\r\n.\r\n"
- mailserver = ('smtp.cc.ncu.edu.tw', 587)
- clientSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- ssl_sock = context.wrap_socket(clientSocket, server_hostname = 'smtp.cc.ncu.edu.tw')
- clientSocket.connect(mailserver)
- recv = clientSocket.recv(1024).decode()
- print(recv)
- if recv[:3] != '220':
- print('220 reply not received from server.')
- heloCommand = 'HELO Alice\r\n'
- clientSocket.send(heloCommand.encode())
- recv1 = clientSocket.recv(1024).decode()
- print(recv1)
- if recv1[:3] != '250':
- print('250 reply not received from server.')
- username = "" #YourEmailAddress
- password = "" #YourEmailPassword
- base64_usernameAndPassword = ("\x00" + username + "\x00" + password).encode()
- base64_usernameAndPassword = base64.b64encode(base64_usernameAndPassword)
- authMsg = "AUTH PLAIN ".encode() + base64_usernameAndPassword + "\r\n".encode()
- clientSocket.send(authMsg)
- recv_auth = clientSocket.recv(1024)
- print(recv_auth.decode())
- mailFrom = "MAIL FROM: <>\r\n" #YourEmailAddress(SEND)
- clientSocket.send(mailFrom.encode())
- recv = clientSocket.recv(1024).decode()
- print("MAIL FROM after: "+recv)
- rcptTo = "RCPT TO:<>\r\n" #YourEmailAddress(RCV)
- clientSocket.send(rcptTo.encode())
- recv = clientSocket.recv(1024).decode()
- print("MAIL FROM after: "+ recv)
- data = "DATA\r\n"
- clientSocket.send(data.encode())
- recv = clientSocket.recv(1024).decode()
- print("DATA after: " + recv)
- Subject = "Subject: blyat\r\n"
- clientSocket.send(Subject.encode())
- clientSocket.send(msg.encode())
- clientSocket.send("\r\n".encode())
- clientSocket.send(endmsg.encode())
- recv = clientSocket.recv(1024).decode()
- print("after send message:" + recv)
- quit = "QUIT\r\n"
- clientSocket.send(quit.encode())
- recv = clientSocket.recv(1024).decode()
- print(recv)
- clientSocket.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement