I am trying to send email via Python but I am having an error.
This is my code:
import smtplib
content = 'example bla bla'
mail = smtplib.SMTP('localhost')
mail.ehlo()
mail.starttls()
mail.login('from@example.com','password')
mail.sendmail('from@example.com','to@example.com',content)
mail.close()
When I run the file, this error shows up:
Traceback (most recent call last):
File "SendEmail.py", line 11, in <module>
mail.starttls()
File "/usr/lib/python2.7/smtplib.py", line 637, in starttls
raise SMTPException("STARTTLS extension not supported by server.")
smtplib.SMTPException: STARTTLS extension not supported by server.
There are posts about other people with the same problem but usually is just the order of the commands that is wrong (like this one) and apparently mine is correct.
If I change mail = smtplib.SMTP('localhost')
to mail = smtplib.SMTP('smtp.gmail.com', 587)
it works well. That makes me think that the problem may be in the configuration of the "localhost" but if I open http://localhost
in the browser the page "It works" is presented so I think the localhost is well configured.
Does anyone know where can be the problem?