-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to set TLS 1.2 smtp? #160
Comments
I'd recommend creating custom backend class. |
Can you please elaborate more here? How do you setup the custom backend? I'm getting some SSL versions mismatch. |
Hello, @mabounassif |
Hello @lavr ! message = emails.Message(
subject=JinjaTemplate(subject_template),
html=JinjaTemplate(html_template),
mail_from=(settings.emails_from_name, settings.emails_from_email),
)
smtp_options = {"host": settings.smtp_host, "port": settings.smtp_port, "fail_silently": False}
smtp_options["ssl"] = True
smtp_options["user"] = settings.smtp_user
smtp_options["password"] = settings.smtp_password
# Add common template environment elements
environment["server_host"] = settings.server_host
environment["server_name"] = settings.server_name
environment["server_bot"] = settings.server_bot
response = message.send(to=email_to, render=environment, smtp=smtp_options) The error I'm getting is: File "/usr/local/lib/python3.10/site-packages/emails/message.py", line 406, in send
return smtp.sendmail(**params)
File "/usr/local/lib/python3.10/site-packages/emails/backend/smtp/backend.py", line 115, in sendmail
response = send(from_addr=from_addr,
File "/usr/local/lib/python3.10/site-packages/emails/backend/smtp/backend.py", line 80, in wrapper
return func(*args, **kwargs)
File "/usr/local/lib/python3.10/site-packages/emails/backend/smtp/backend.py", line 100, in _send
response.raise_if_needed()
File "/usr/local/lib/python3.10/site-packages/emails/backend/response.py", line 18, in raise_if_needed
raise self._exc
emails.backend.smtp.exceptions.SMTPConnectNetworkError: [Errno 1] [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1007): None |
One more thing to add is that I'm using Outlook SMTP settings as specified here. I've setup an App password for the outlook account. |
Running something as simple as: import socket
import ssl
hostname = 'smtp-mail.outlook.com'
port = 587
context = ssl.create_default_context()
with socket.create_connection((hostname, port)) as sock:
with context.wrap_socket(sock, server_hostname=hostname) as ssock:
print(ssock.version()) leads to the same issue |
Looks like 587 is not ssl port
|
In python-email there is |
Bingo! Thank you :) |
As the SMTP is required TLS 1.2, how to force smtp use TLS 1.2?
The text was updated successfully, but these errors were encountered: