我只是在试用电子邮件模块,我甚至无法让它最简单的部分工作!我正在使用电子邮件模块文档here中的第一个示例。当我运行这个程序时:
# Import smtplib for the actual sending function
import smtplib
# Import the email modules we'll need
from email.mime.text import MIMEText
# Open a plain text file for reading. For this example, assume that
# the text file contains only ASCII characters.
with open('email.txt') as fp:
# Create a text/plain message
msg = MIMEText(fp.read())
# me == the sender's email address
# you == the recipient's email address
msg['Subject'] = 'Subject'
msg['From'] = 'user@example.com'
msg['To'] = 'otheruser@example.com'
# Send the message via our own SMTP server.
s = smtplib.SMTP('localhost')
s.send_message(msg)
s.quit()
我收到此错误消息:
Traceback (most recent call last):
File "C:/Users/User/emailTest.py", line 20, in <module>
s = smtplib.SMTP('localhost')
File "C:\Users\User\AppData\Local\Programs\Python\Python35\lib\smtplib.py", line 251, in __init__
(code, msg) = self.connect(host, port)
File "C:\Users\User\AppData\Local\Programs\Python\Python35\lib\smtplib.py", line 335, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "C:\Users\User\AppData\Local\Programs\Python\Python35\lib\smtplib.py", line 306, in _get_socket
self.source_address)
File "C:\Users\User\AppData\Local\Programs\Python\Python35\lib\socket.py", line 711, in create_connection
raise err
File "C:\Users\User\AppData\Local\Programs\Python\Python35\lib\socket.py", line 702, in create_connection
sock.connect(sa)
ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it