python实现邮件客户端_SMTP邮件客户端Python
我必須用Python編寫一個用于類的SMTP郵件客戶端,并且在作業的第一部分中卡住了。在經歷了很多麻煩之后,我已經走到了這一步(目前使用免費的便攜式SMTP服務器,但以后將需要使用SSL或TLS用于gmail)。下面是我的代碼。我得到一個500語法錯誤,當它到達RCPT到代碼的一部分。有人能幫忙嗎?from socket import *
msg = "\r\n I love computer networks!"
endmsg = "\r\n.\r\n"
# Choose a mail server
mailServer = 'localhost'
mailPort = 25
# Create socket called clientSocket and establish a TCP connection with mailserver
clientSocket = socket(AF_INET,SOCK_STREAM)
clientSocket.connect((mailServer, mailPort))
recv = clientSocket.recv(1024)
print 'test'
print recv
if recv[:3] != '220':
print '220 reply not received from server.'
# Send HELLO command and print server response.
helloCommand = 'HELO Alice\r\n';
clientSocket.send(helloCommand)
recv1 = clientSocket.recv(1024)
print recv1
if recv1[:3] != '250':
print '250 reply not received from server.'
# Send MAIL FROM command and print server response.
#command = "STARTTLS\r\n"
#clientSocket.send(command)
#recva = clientSocket.recv(1024)
#print(recva)
mailfromCommand = 'MAIL FROM: \r\n.'
clientSocket.send(mailfromCommand)
recv1 = clientSocket.recv(1024)
print(recv1)
if recv1[:3] != '250':
print('mail from 250 reply not received from server.')
# Send RCPT TO command and print server response.
rcpttoCommand = 'RCPT TO: \r\n'
clientSocket.send(rcpttoCommand)
recv1 = clientSocket.recv(1024)
print(recv1)
if recv1[:3] != '250':
print('rcpt to 250 reply not received from server.')
# Send DATA command and print server response
dataCommand = 'Data'
print(dataCommand)
clientSocket.send(dataCommand)
recv1 = clientSocket.recv(1024)
print(recv1)
if recv1[:3] != '250':
print('data 250 reply not received from server.')
# Send message data.
message = raw_input('Enter Message Here: ')
# Fill in end# Message ends with a single period.
mailMessageEnd = '\r\n.\r\n'
clientSocket.send(message + mailMessageEnd)
recv1 = clientSocket.recv(1024)
print(recv1)
if recv1[:3] != '250':
print('end msg 250 reply not received from server.')
# Send QUIT command and get server response.
quitCommand = 'Quit\r\n'
print(quitCommand)
clientSocket.send(quitCommand)
recv1 = clientSocket.recv(1024)
print(recv1)
if recv1[:3] != '250':
print('quit 250 reply not received from server.')
pass
if __name__ == '__main__':
main()
結果:test
220 localhost
250 Hello localhost
250 mail@mail.com Address Okay
RCPT TO:
500 Syntax Error
rcpt to 250 reply not received from server.
Data
總結
以上是生活随笔為你收集整理的python实现邮件客户端_SMTP邮件客户端Python的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: php 可维护性的代码,软件的可复用性和
- 下一篇: python开源考试_可能是 Pytho