Difference between revisions of "Smtp certs"

From UVOO Tech Wiki
Jump to navigation Jump to search
 
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
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

https://stackoverflow.com/questions/54976051/how-to-accept-self-signed-certificate-from-e-mail-server-via-smtplib-tsl

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()