0

I am trying to send email using python but i am getting error while sending the email, i have also tried with both the commands (with python2 and python3) while executing the code

import smtplib,ssl

content= "prince kumar"

mail = smtplib.SMTP_SSL('gmail-smtp-in.l.google.com', 25)
#mail.ehlo()

#mail.starttls()

mail.login('kmrprncanu@gmail.com','83412adsf234sad')

mail.sendmail('kmrprncanu@gmail.com', 'kmrprnc44@gmail.com',content)

mail.close()

Error :

  root@localhost:~# python smtp.py 
   Traceback (most recent call last):
 File "smtp.py", line 6, in <module>
mail = smtplib.SMTP_SSL('smtp.gmail.com', 587)
File "/usr/lib/python2.7/smtplib.py", line 802, in __init__
 SMTP.__init__(self, host, port, local_hostname, timeout)
File "/usr/lib/python2.7/smtplib.py", line 256, in __init__
(code, msg) = self.connect(host, port)
File "/usr/lib/python2.7/smtplib.py", line 317, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "/usr/lib/python2.7/smtplib.py", line 808, in _get_socket
new_socket = ssl.wrap_socket(new_socket, self.keyfile, self.certfile)
File "/usr/lib/python2.7/ssl.py", line 949, in wrap_socket
ciphers=ciphers)
File "/usr/lib/python2.7/ssl.py", line 617, in __init__
  self.do_handshake()
 File "/usr/lib/python2.7/ssl.py", line 846, in do_handshake
self._sslobj.do_handshake()
 ssl.SSLError: [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:726)
AzyCrw4282
  • 7,222
  • 5
  • 19
  • 35
prince kumar
  • 1
  • 1
  • 1
  • try https://stackoverflow.com/questions/19390267/python-3-smtplib-exception-ssl-wrong-version-number-logging-in-to-outlook – ewokx Jul 07 '20 at 09:30

1 Answers1

0

It looks like the error is stemming from the wrong use of a port number.

You need to change the port from 25 to 465 or 587(ideally) to use SMTP with SSL; port 25 is often used for non-encrypted email. So apply the change to this line and it should solve your problem.

mail = smtplib.SMTP_SSL('gmail-smtp-in.l.google.com', 587)
AzyCrw4282
  • 7,222
  • 5
  • 19
  • 35