Sending Email using examples From Tutorials

Jason Friedman jsf80238 at gmail.com
Sat Jan 27 23:02:35 EST 2018


>
> import smtplib
> server = smtplib.SMTP('localhost')
> server.sendmail('gg77galvez at yahoo.com',
> """To: gg.galvez at gmail.com
> From: gg77galvez at yahoo.com
>
> Beware the Ides of March.
> """)
> server.quit()
>
> when running this I get the following message. Please help:
>
> Traceback (most recent call last):
>   File "D:\ProgramDev\PythonDev\sendemail.py", line 3, in <module>
>     server = smtplib.SMTP('localhost')
>   File "C:\Users\Admin\AppData\Local\Programs\Python\Python36-32\lib\smtplib.py",
> line 251, in __init__
>     (code, msg) = self.connect(host, port)
>   File "C:\Users\Admin\AppData\Local\Programs\Python\Python36-32\lib\smtplib.py",
> line 335, in connect
>     self.sock = self._get_socket(host, port, self.timeout)
>   File "C:\Users\Admin\AppData\Local\Programs\Python\Python36-32\lib\smtplib.py",
> line 306, in _get_socket
>     self.source_address)
>   File "C:\Users\Admin\AppData\Local\Programs\Python\Python36-32\lib\socket.py",
> line 722, in create_connection
>     raise err
>   File "C:\Users\Admin\AppData\Local\Programs\Python\Python36-32\lib\socket.py",
> line 713, in create_connection
>     sock.connect(sa)
> ConnectionRefusedError: [WinError 10061] No connection could be made
> because the target machine actively refused it


Your code is fine, but to send mail you need a SMTP server that accepts
connections.  With:
server = smtplib.SMTP('localhost')

your code is saying that you have an SMTP server listening on your
localhost.  I don't think you do.



More information about the Python-list mailing list