import smtplib
smtp = smtplib.SMTP()
smtp.connect('smtp.gmail.com','587')
(220, b'smtp.gmail.com ESMTP h15-v6sm187291iog.48 - gsmtp')
smtp.starttls()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/smtplib.py", line 771, in starttls
server_hostname=self._host)
File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 412, in wrap_socket
session=session
File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 843, in _create
owner=self, session=self._session,
ValueError: server_hostname cannot be an empty string or start with a leading dot.
I am using python 3.7 on Mac and cannot perform a tls handshake with gmail. This code works on python 2.7, and on my Ubuntu server using python 3.5.2. Does anyone know what could be causing this error?
It seems a python3.7 bug, pass the hostname to smtplib.SMTP will fix it
smtp = smtplib.SMTP('smtp.gmail.com')
smtp.connect('smtp.gmail.com','587')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With