使用Python发送电子邮件

时间:2014-11-16 21:15:35

标签: python

我正在尝试使用Python发送电子邮件:

import smtplib

s = smtplib.SMTP('localhost')
s.sendmail('xxxxxxxxxxx@yahoo.com', ['xxxxxxxx@gmail.com'], 'HELLO')
s.quit()

但是会弹出这个错误:

     server = smtplib.SMTP(SERVER)
  File "C:\Python27\lib\smtplib.py", line 251, in __init__
    (code, msg) = self.connect(host, port)
  File "C:\Python27\lib\smtplib.py", line 311, in connect
    self.sock = self._get_socket(host, port, self.timeout)
  File "C:\Python27\lib\smtplib.py", line 286, in _get_socket
    return socket.create_connection((host, port), timeout)
  File "C:\Python27\lib\socket.py", line 571, in create_connection
    raise err
error: [Errno 10061] No connection could be made because the target machine actively refused it

因为Gmail阻止了我,它无效吗?我不想连接到其他邮件服务器来发送我的电子邮件。没有它们还可以吗?

1 个答案:

答案 0 :(得分:0)

将'localhost'更改为'smtp.gmail.com'