您好我正在尝试让python 3从Ubuntu发送一封简单的电子邮件。
我创建了一个简单的smpt服务器: python -m smtpd -n -c DebuggingServer localhost:1025
以下是我的电子邮件服务器的代码:
import smtplib
message = """
Hello
"""
sender = "dancbtalk@yahoo.com"
receivers=["dancbtalk@yahoo.com"]
try:
smtpObj = smtplib.SMTP('localhost', 1025)
smtpObj.sendmail(sender, receivers, message)
print "Successfully sent email"
except smtplib.SMTPException:
print "Error: unable to send email"
我的输出显示电子邮件已成功发送,但当我实际检查该电子邮件帐户时,它没有收到任何内容。我已尝试使用多个电子邮件帐户。
答案 0 :(得分:2)
您的邮件没有任何标题。或者更确切地说,您的邮件只包含 标题,其中任何一个都不会被识别为有效。至少你可能想要添加Subject,From和To标题。 E.g。
sender = "dancbtalk@yahoo.com"
receivers = ["dancbtalk@yahoo.com"]
headers = """From: %s
To: %s
Subject: Hello
""" % (sender, ", ".join(receivers)
message = headers + "\n" + """
Hello
"""