你好,我正在尝试让 python 3 从 Ubuntu 发送一封简单的电子邮件。
我启动了一个简单的 smtp 服务器:
python -m smtpd -n -c 调试服务器本地主机:1025
以下是我的电子邮件服务器的代码:
import smtplib
message = """
Hello
"""
sender = "[email protected] /cdn-cgi/l/email-protection"
receivers=["[email protected] /cdn-cgi/l/email-protection"]
try:
smtpObj = smtplib.SMTP('localhost', 1025)
smtpObj.sendmail(sender, receivers, message)
print "Successfully sent email"
except smtplib.SMTPException:
print "Error: unable to send email"
我的输出显示电子邮件已成功发送,但当我实际检查该电子邮件帐户时,它没有收到任何内容。我已经用几个电子邮件帐户尝试过此操作。
您的消息没有任何标题。或者更准确地说,您的消息包含only标头,其中任何一个都不会被识别为有效。至少您可能想要添加“主题”、“发件人”和“收件人”标头。例如。
sender = "[email protected] /cdn-cgi/l/email-protection"
receivers = ["[email protected] /cdn-cgi/l/email-protection"]
headers = f"""From: {sender}
To: {", ".join(receivers)}
Subject: Hello
"""
message = headers + "\n" + """
Hello
"""
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)