13
I want to send emails with my python script, but unfortunately it's not as straightforward and smooth as php, where I can just use mail() function.
I've used this example:
import smtplib
FROM = "sender@example.com"
TO = ["me@gmail.com"]
SUBJECT = "Hello!"
TEXT = "This message was sent with Python's smtplib."
server = smtplib.SMTP(SERVER)
server.sendmail(FROM, TO, message)
server.quit()
but it only returns a whole bunch of errors I don't even know the meaning of...
Traceback (most recent call last):
File "mylo.py", line 70, in <module>
sys.exit(main())
File "mylo.py", line 66, in main
send_mail()
File "mylo.py", line 37, in send_mail
server = smtplib.SMTP(SERVER)
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/smtplib.py", line 239, in __init__
(code, msg) = self.connect(host, port)
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/smtplib.py", line 295, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/smtplib.py", line 273, in _get_socket
return socket.create_connection((port, host), timeout)
File "/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/socket.py", line 512, in create_connection
raise error, msg
socket.error: [Errno 61] Connection refused
How do I send emails with python?