I\'ve been trying (and failing) to figure out how to send email via Python.
Trying the example from here: http://docs.python.org/library/smtplib.html#smtplib.SMTP
Then I had trie to sent email through smtp.gmail.com, I had the same errors. In my case the Internet provider had close the port 25 (and also 587 and other) for outgoing connections from the IP addresses (from my network) to the external network, leaving open the 25th port only for its mail server. So, at first try:
telnet smtp.gmail.com 587
(587 it your port)
By doing this you can understand, if your port is closed by the Internet provider. You can contact your provider and ask them to open a port for you. My solution was connecting to other network (with open port) Here is the code I used:
gmailaddress = "youremailadress@gmail.com"
gmailpassword = "7777777"
mailto = "youremailadress@gmail.com"
msg = input("What is your message? \n ")
mailServer = smtplib.SMTP('smtp.gmail.com' , 587)
mailServer.starttls()
mailServer.login(gmailaddress , gmailpassword)
mailServer.sendmail(gmailaddress, mailto , msg)
print(" \n Sent!")
mailServer.quit()```