Skip to content

Commit 4a24f2c

Browse files
Merge pull request #784 from w1ll1am23/ignore_smtp_certification_verification
Add env variable for bypassing certificate verification for SMTP
2 parents 9a7fb5c + 18af6a0 commit 4a24f2c

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

CONTRIBUTORS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,8 @@ Copyright (C) 2024-2025 Calibre-Web Automated contributors
325325
- chad3814 (2 commits)
326326
- coissac (2 commits)
327327
- FennyFatal (2 commits)
328+
- itsmarcy (2 commits)
329+
- JamesRy96 (2 commits)
328330
- sethvoltz (2 commits)
329331
- Strubbl (2 commits)
330332
- tecosaur (2 commits)

cps/tasks/mail.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,15 @@ def run(self, worker_thread):
181181
def send_standard_email(self, msg):
182182
use_ssl = int(self.settings.get('mail_use_ssl', 0))
183183
timeout = 600 # set timeout to 5mins
184+
use_unverified_context = os.getenv("SMTP_ALLOW_UNVERIFIED_SSL", "false").strip().lower() in ("1", "true", "yes", "on")
184185

185186
# on python3 debugoutput is caught with overwritten _print_debug function
186187
log.debug("Start sending e-mail")
187188
if use_ssl == 2:
188189
context = ssl.create_default_context()
190+
if use_unverified_context:
191+
context.check_hostname = False
192+
context.verify_mode = ssl.CERT_NONE
189193
self.asyncSMTP = EmailSSL(self.settings["mail_server"], self.settings["mail_port"],
190194
timeout=timeout, context=context)
191195
else:
@@ -196,6 +200,9 @@ def send_standard_email(self, msg):
196200
self.asyncSMTP.set_debuglevel(1)
197201
if use_ssl == 1:
198202
context = ssl.create_default_context()
203+
if use_unverified_context:
204+
context.check_hostname = False
205+
context.verify_mode = ssl.CERT_NONE
199206
self.asyncSMTP.starttls(context=context)
200207
if self.settings["mail_password_e"]:
201208
self.asyncSMTP.login(str(self.settings["mail_login"]), str(self.settings["mail_password_e"]))

0 commit comments

Comments
 (0)