【发布时间】:2021-12-02 06:41:18
【问题描述】:
这里有关于如何发送电子邮件的文档:https://docs.python.org/3/library/email.examples.html
我尝试运行的完整代码是...
# Import smtplib for the actual sending function
import smtplib
# Import the email modules we'll need
from email.message import EmailMessage
# Open the plain text file whose name is in textfile for reading.
# Create a text/plain message
msg = EmailMessage("HI")
# me == the sender's email address
# you == the recipient's email address
msg['Subject'] = "SubjectLine"
msg['From'] = aaaaa@gmail.com
msg['To'] = aaaaa@yahoo.com
# Send the message via our own SMTP server.
s = smtplib.SMTP('localhost')
s.send_message(msg)
s.quit()
第 16 行代码出现错误
msg['Subject'] = "SubjectLine"
错误是:'str' object has no attribute 'header_max_count'
【问题讨论】:
-
"第 16 行代码出现错误" ...您确定吗?此行与政策完全无关,符合官方文档的指导。
-
您能解释一下您认为在
EmailMessage("HI")行中传递给EmailMessage的论点实际上是做什么的...?您是否阅读了the documentation forEmailMessage以了解您应该 作为参数传递的内容?您能否分享一下您理解"HI"在这种情况下是该函数的有效参数的文档? -
感谢您的帮助。我将删除这篇文章作为修改我的问题。