0

I am trying to send mail using twisted esmtp using smtp.gmail.com. While I am trying to send mail using host as "smtp.gmail.com" the code works fine and mail was sent successfully. But when I am trying to use an IP ( smtp.gmail.com 'ip') in host I am getting below error.

Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/twisted/protocols/tls.py", line 415, in dataReceived
    self._write(bytes)
  File "/usr/local/lib/python2.7/dist-packages/twisted/protocols/tls.py", line 554, in _write
    sent = self._tlsConnection.send(toSend)
  File "/usr/local/lib/python2.7/dist-packages/OpenSSL/SSL.py", line 1539, in send
    result = _lib.SSL_write(self._ssl, buf, len(buf))
  File "/usr/local/lib/python2.7/dist-packages/OpenSSL/SSL.py", line 1136, in wrapper
    callback(Connection._reverse_mapping[ssl], where, return_code)
--- <exception caught here> ---
  File "/usr/local/lib/python2.7/dist-packages/twisted/internet/_sslverify.py", line 1121, in infoCallback
    return wrapped(connection, where, ret)
  File "/usr/local/lib/python2.7/dist-packages/twisted/internet/_sslverify.py", line 1220, in _identityVerifyingInfoCallback
    verifyHostname(connection, self._hostnameASCII)
  File "/usr/local/lib/python2.7/dist-packages/service_identity/pyopenssl.py", line 48, in verify_hostname
    obligatory_ids=[DNS_ID(hostname)],
  File "/usr/local/lib/python2.7/dist-packages/service_identity/_common.py", line 245, in __init__
    raise ValueError("Invalid DNS-ID.")
exceptions.ValueError: Invalid DNS-ID.

I have also tried by making an entry in /etc/hosts file also but facing the same issue. Also If I run this code using smtplib library the mail sent successfully using ip also.

Ashish Kumar Verma
  • 1,322
  • 1
  • 13
  • 21
  • It doesn't look like the certificate presented at smtp.gmail.com:465 claims an IP-based identity. So your TLS client configuration is rejecting the certificate as not being valid to prove the authority for some IP address you're connecting to. This seems to be correct validation behavior and is what any TLS client should do. If the stdlib smtplib module does not fail the same way, it is because it is not using TLS or it is using TLS in an unsafe way. – Jean-Paul Calderone Nov 26 '20 at 14:52
  • Thanks for explanation @Jean-PaulCalderone. I have another SMTP server which is bound to ip based identity but I am facing the same problem there also. – Ashish Kumar Verma Nov 26 '20 at 19:04

0 Answers0