auh: Add port 465 and 587 client support
PATCH 1/1 auh: Add port 465 and 587 client support
Signed-off-by Armin Kuster <[email protected]>
--- modules/utils/emailhandler.py | 23 +++++++++++++++++++++-- upgrade-helper.conf | 3 +++ 2 files changed, 24 insertions(+), 2 deletions(-)
modules/utils/emailhandler.py +21 -2
@@ -27,7 +27,7 @@ import os import logging as log from logging import error as E from logging import info as I -from smtplib import SMTP +from smtplib import SMTP, SMTP_SSL import mimetypes from email.mime.text import MIMEText from email.mime.base import MIMEBase
@@ -35,12 +35,14 @@ from email.mime.multipart import MIMEMultipart from email.generator import Generator import shutil from io import StringIO +import ssl class Email(object): def __init__(self, settings): self.smtp_host = None self.smtp_port = None self.from_addr = None + self.from_addr_pswd = None if "smtp" in settings: smtp_entry = settings["smtp"].split(":") if len(smtp_entry) == 1:
@@ -57,6 +59,13 @@ class Email(object): else: E(" 'From' address not set! Sending emails disabled!") + if "email_client_pswd" in settings: + self.from_addr_pswd = settings["email_client_pswd"] + + if self.smtp_port != '25': + if self.from_addr_pswd == None: + E(" Port %s needs a password, None set!" % self.smtp_port) + super(Email, self).__init__() def send_email(self, to_addr, subject, text, files=[], cc_addr=None):
@@ -101,7 +110,17 @@ class Email(object): msg_text = out.getvalue() try: - smtp = SMTP(self.smtp_host, self.smtp_port) + if self.smtp_port == '465': + smtp = SMTP_SSL(self.smtp_host, self.smtp_port) + smtp.login(self.from_addr, self.from_addr_pswd) + else: + smtp = SMTP(self.smtp_host, self.smtp_port) + if self.smtp_port == '587': + smtp.ehlo() + smtp.starttls(context=ssl.create_default_context()) + smtp.ehlo() + smtp.login(self.from_addr, self.from_addr_pswd) + smtp.sendmail(self.from_addr, to_addr, msg_text) if cc_addr is not None: smtp.sendmail(self.from_addr, cc_addr, msg_text)
upgrade-helper.conf +3 -0
@@ -25,6 +25,9 @@ # If no port is specified, port 25 is assumed. #smtp=smtp.my-server.com:25 +# Define a password needed to contect to email server +#email_client_pswd= + # from whom should the e-mails be sent (mandatory if --send-emails is passed). # Also sets the email address of the author of automated commits. #[email protected]
Signature · 1 line
2.17.1