Difference between revisions of "Smtp certs"
Jump to navigation
Jump to search
(Created page with "``` import smtplib, ssl port = 587 smtp_server = "smtp-na1.towerswatson.com" context = ssl.create_default_context() with smtplib.SMTP(smtp_server, port) as server: server....") |
|||
| (One intermediate revision by the same user not shown) | |||
| Line 1: | Line 1: | ||
| + | https://stackoverflow.com/questions/54976051/how-to-accept-self-signed-certificate-from-e-mail-server-via-smtplib-tsl | ||
| + | |||
``` | ``` | ||
import smtplib, ssl | import smtplib, ssl | ||
port = 587 | port = 587 | ||
| − | smtp_server = " | + | smtp_server = "foo.example" |
context = ssl.create_default_context() | context = ssl.create_default_context() | ||
with smtplib.SMTP(smtp_server, port) as server: | with smtplib.SMTP(smtp_server, port) as server: | ||
| Line 8: | Line 10: | ||
server.starttls(context=context) | server.starttls(context=context) | ||
server.ehlo() | server.ehlo() | ||
| + | ``` | ||
| + | |||
| + | ``` | ||
| + | |||
| + | import smtplib, ssl | ||
| + | context = ssl._create_unverified_context() | ||
| + | with smtplib.SMTP_SSL("domain.tld", 465, context=context) as server: | ||
| + | server.login(user, password) | ||
| + | server.sendmail(sender_email, receiver_email, message.as_string()) | ||
| + | ``` | ||
| + | ``` | ||
| + | con = MySMTP(server, port) | ||
| + | context = ssl.create_default_context(cafile=PATH_TO_CERTIFICATE_AUTHORITY_ROOT_CRT_FILE) | ||
| + | con.starttls(context=context) | ||
| + | con.login(user, pass) | ||
| + | con.quit() | ||
``` | ``` | ||
Latest revision as of 00:30, 10 May 2022
import smtplib, ssl
port = 587
smtp_server = "foo.example"
context = ssl.create_default_context()
with smtplib.SMTP(smtp_server, port) as server:
server.ehlo()
server.starttls(context=context)
server.ehlo()
<br />import smtplib, ssl
context = ssl._create_unverified_context()
with smtplib.SMTP_SSL("domain.tld", 465, context=context) as server:
server.login(user, password)
server.sendmail(sender_email, receiver_email, message.as_string())
con = MySMTP(server, port) context = ssl.create_default_context(cafile=PATH_TO_CERTIFICATE_AUTHORITY_ROOT_CRT_FILE) con.starttls(context=context) con.login(user, pass) con.quit()