smtp(使用hmailserver设置)localhost到gmail消息,在Windows10上发送不正常的python

时间:2017-10-27 08:11:30

标签: python smtplib hmail-server

我正在尝试编写一个python代码,它会向我的电子邮件帐户发送错误消息。我使用smtplib从localhost发送消息到我的Gmail帐户。我正在尝试跟随jupyter笔记本:

import smtplib

SERVER = "localhost"
LOGIN = "sourabh@localhost.com"
PASSWORD = "sourabh"

FROM = "sourabh@localhost.com"
TO = ["sourabhjbp@gmail.com"] # must be a list
SUBJECT = "Hello!"

TEXT = "This message was sent with Python's smtplib."

# Prepare actual message
message = """\
From: %s
To: %s
Subject: %s

%s
""" % (FROM, ", ".join(TO), SUBJECT, TEXT)

server = smtplib.SMTP(SERVER,port=25)
server.set_debuglevel(1)
server.login(LOGIN, PASSWORD)
server.sendmail(FROM, TO, message)
server.quit()

退出消息“(221,'goodbye')”。以下是完整的调试日志,

send: 'ehlo [192.168.56.1]\r\n'
reply: '250-localhost\r\n'
reply: '250-SIZE 20480000\r\n'
reply: '250-AUTH LOGIN PLAIN\r\n'
reply: '250 HELP\r\n'
reply: retcode (250); Msg: localhost
SIZE 20480000
AUTH LOGIN PLAIN
HELP
send: 'AUTH PLAIN AHNvdXJhYmhAbG9jYWxob3N0LmNvbQBzb3VyYWJo\r\n'
reply: '235 authenticated.\r\n'
reply: retcode (235); Msg: authenticated.
send: 'mail FROM:<sourabh@localhost.com> size=115\r\n'
reply: '250 OK\r\n'
reply: retcode (250); Msg: OK
send: 'rcpt TO:<sourabhjbp@gmail.com>\r\n'
reply: '250 OK\r\n'
reply: retcode (250); Msg: OK
send: 'data\r\n'
reply: '354 OK, send.\r\n'
reply: retcode (354); Msg: OK, send.
data: (354, 'OK, send.')
send: "From: sourabh@localhost.com\r\nTo: sourabhjbp@gmail.com\r\nSubject: Hello!\r\n\r\nThis message was sent with Python's smtplib.\r\n.\r\n"
reply: '250 Queued (0.032 seconds)\r\n'
reply: retcode (250); Msg: Queued (0.032 seconds)
data: (250, 'Queued (0.032 seconds)')
send: 'quit\r\n'
reply: '221 goodbye\r\n'
reply: retcode (221); Msg: goodbye

1 个答案:

答案 0 :(得分:0)

线 回复:retcode(250);消息:已排队(0.032秒) 数据:(250,“已排队(0.032秒)”)

说hMailServer已成功接受您的邮件:

您现在应该在hMailServer DATA文件夹的根目录中看到一个新的* .eml文件。 (名称为{3f20b09b-2a35-4a16-a7e9-a510ea0f5eae.eml的文件} 其中包含您通过Python发送的消息。它将自动删除 如果您的电子邮件已到达收件人。

有关更多信息,请运行hMailAdmin,转到设置并启用所有“日志记录”复选框 并重新启动您的hMailServer Windows服务/守护进程(或从高架Windows命令提示符处运行net hmailserver stop和net hmailserver start。

PS:服务重新启动后,需要关闭hMailAdmin(或任何其他COM-Client) 并重新启动(只需退出hMailAdmin并重新运行即可)。