Signed-off-by: Armin Kuster <akuster...@gmai.com> --- modules/utils/emailhandler.py | 23 +++++++++++++++++++++-- upgrade-helper.conf | 3 +++ 2 files changed, 24 insertions(+), 2 deletions(-)
diff --git a/modules/utils/emailhandler.py b/modules/utils/emailhandler.py index 8c8b85b..a70bf23 100644 --- a/modules/utils/emailhandler.py +++ b/modules/utils/emailhandler.py @@ -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) diff --git a/upgrade-helper.conf b/upgrade-helper.conf index 5696564..3a5b3db 100644 --- a/upgrade-helper.conf +++ b/upgrade-helper.conf @@ -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. #from=u...@not.set -- 2.17.1
-=-=-=-=-=-=-=-=-=-=-=- Links: You receive all messages sent to this group. View/Reply Online (#52574): https://lists.yoctoproject.org/g/yocto/message/52574 Mute This Topic: https://lists.yoctoproject.org/mt/81078476/21656 Group Owner: yocto+ow...@lists.yoctoproject.org Unsubscribe: https://lists.yoctoproject.org/g/yocto/unsub [arch...@mail-archive.com] -=-=-=-=-=-=-=-=-=-=-=-