【发布时间】:2021-12-01 05:15:33
【问题描述】:
我正在尝试使用 smtplib 发送电子邮件,而不在本地存储 smtp 凭据。我找到了这篇文章https://www.tutorialspoint.com/python/python_sending_email.htm,但出现错误。我对 smtplib 相当陌生。任何帮助将不胜感激。
#!/usr/bin/python
import smtplib
message = """From: From Person <from@fromdomain.com>
To: To Person <to@todomain.com>
MIME-Version: 1.0
Content-type: text/html
Subject: SMTP HTML e-mail test
This is an e-mail message to be sent in HTML format
<b>This is HTML message.</b>
<h1>This is headline.</h1>
"""
try:
smtpObj = smtplib.SMTP('localhost')
smtpObj.sendmail(sender, receivers, message)
print "Successfully sent email"
except SMTPException:
print "Error: unable to send email"
错误
NameError: name 'SMTPException' is not defined
【问题讨论】:
-
这应该可以完成工作:stackoverflow.com/questions/13115724/…
标签: python error-handling smtplib