python:使用python发送电子邮件

时间:2016-10-12 06:07:44

标签: python email

我已经尝试了这个问题的所有答案,但仍然无法弄清楚为什么会显示特定的错误。

 ConnectionRefusedError: [WinError 10061] No connection could be made because the  target machine actively refused it

这是我输入的代码:

 import smtplib

SERVER = "localhost"

FROM = "frommail@example.com"
TO = ["tomail@example.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)

# Send the mail

server = smtplib.SMTP(SERVER)
server.sendmail(FROM, TO, message)
server.quit()

0 个答案:

没有答案