1

我正在尝试编写一个 python 代码,它将错误消息发送到我的电子邮件帐户。我使用 smtplib 从 localhost 向我的 gmail 帐户发送消息。我正在尝试在 jupyter notebook 中关注:

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,'再见')”退出。以下是完整的调试日志,

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
4

1 回答 1

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 并重新运行它)。

于 2019-07-19T04:57:12.403 回答