日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python实现邮件客户端_SMTP邮件客户端Python

發布時間:2023/12/20 python 20 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。