Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Email and TLS only, how ?
#1
Question 
Hi everyone,

I'm currently digging how to send email trough Python with TLS (only)

So it's kind of heavy reading
https://docs.python.org/3/library/ssl.html
https://docs.python.org/3.11/library/ema...mples.html

I created a small SMTP server trough hMailServer for testing purpose.

Firstly I got error because of my Self-signed certificate.
But I've found a workaround there https://stackoverflow.com/a/62982729

So I'm using something like this to test. (and it work)
import ssl
from smtplib import SMTP_SSL

context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
context.verify_mode = ssl.CERT_OPTIONAL 
context.check_hostname = False
context.load_verify_locations(cafile='/pathTOmyCERT')

context.minimum_version = ssl.TLSVersion.TLSv1_3
context.maximum_version = ssl.TLSVersion.TLSv1_3


try:

	with SMTP_SSL("localhost", port=465, context=context) as asmtp:
		print(str(asmtp.noop()))

except Exception as error:
	print(error)
But when I will pass it live, I plan to not allow self-signed certificate. So what could be the best to ensure the highest security level ?

It's weird because the documentation claim for create_default_context(): https://docs.python.org/3/library/ssl.ht...lt_context
create_default_context() Wrote:The settings are chosen by the ssl module, and usually represent a higher security level than when calling the SSLContext constructor directly.

is that so ?

Because if
context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
context.minimum_version = ssl.TLSVersion.TLSv1_3
context.maximum_version = ssl.TLSVersion.TLSv1_3
Only Allow TLS 1.3 What could be the benefits of create_default_context() ? and how to use it to only allow TLS 1.3 ?

Thanks.
[Image: NfRQr9R.jpg]
Reply
#2
context = ssl.create_default_context(ssl.PROTOCOL_TLS_CLIENT)
is not working :/
[Image: NfRQr9R.jpg]
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  An email with inline jpg cannot be read by all email clients fpiraneo 4 4,037 Feb-25-2018, 07:17 PM
Last Post: fpiraneo
  Email - Send email using Windows Live Mail cyberzen 2 5,961 Apr-13-2017, 03:14 AM
Last Post: cyberzen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020