Velvet Star Monitor

Standout celebrity highlights with iconic style.

updates

How to fix ssl.SSLError: [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1056)?

Writer Olivia Zamora

I am trying to send an email with python, but it keeps saying ssl.SSLError: [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1056). Here is my code:

server = smtplib.SMTP_SSL('smtp.mail.com', 587)
server.login("", "password")
server.sendmail(
"",
"",
"email text")
server.quit()

Do you know what is wrong?

2

3 Answers

The port for SSL is 465 and not 587, however when I used SSL the mail arrived to the junk mail.

For me the thing that worked was to use TLS over regular SMTP instead of SMTP_SSL.

Note that this is a secure method as TLS is also a cryptographic protocol (like SSL).

import smtplib, ssl
port = 587 # For starttls
smtp_server = "smtp.gmail.com"
sender_email = ""
receiver_email = ""
password = input("Type your password and press enter:")
message = """\
Subject: Hi there
This message is sent from Python."""
context = ssl.create_default_context()
with smtplib.SMTP(smtp_server, port) as server: server.ehlo() # Can be omitted server.starttls(context=context) server.ehlo() # Can be omitted server.login(sender_email, password) server.sendmail(sender_email, receiver_email, message)

provided thanks to the real python tutorial.

4

Code to send email via python:

import smtplib , ssl
import getpass
server = smtplib.SMTP_SSL("smtp.gmail.com",465)
server.ehlo()
server.starttls
password = getpass.getpass() # to hide your password while typing (feels cool)
server.login("", password)
server.sendmail("" , "" , "I am trying out python email through coding")
server.quit()

#turn off LESS SECURE APPS to make this work on your gmail

this is how i solved same problem

import ssl
sender = ""
password = "password123"
where_to_email = ""
theme = "this is subject"
message = "this is your message, say hi to reciever"
sender_password = password
session = smtplib.SMTP_SSL('smtp.yandex.ru', 465)
session.login(sender, sender_password)
msg = f'From: {sender}\r\nTo: {where_to_email}\r\nContent-Type: text/plain; charset="utf-8"\r\nSubject: {theme}\r\n\r\n'
msg += message
session.sendmail(sender, where_to_email, msg.encode('utf8'))
session.quit()

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy