Skip to content
Snippets Groups Projects
Commit aed87697 authored by Robert Goldmann's avatar Robert Goldmann
Browse files

BaseUtils: fixed MailHandler

parent 5f0dcff1
Branches
No related tags found
No related merge requests found
......@@ -18,10 +18,21 @@ class MailHandler:
@staticmethod
def send(host: str, port: int, userName: str, password: str, receiverMails: List[str], subject: str, content: str):
for receiver in receiverMails:
message = MailHandler.__create_message(userName, receiver, subject, content)
# Create secure connection with server and send email
context = ssl.create_default_context()
with smtplib.SMTP_SSL(host, port, context=context) as server:
server.login(userName, password)
server.sendmail(userName, receiverMails, message.as_string())
@staticmethod
def __create_message(userName: str, receiver: str, subject: str, content: str) -> MIMEMultipart:
message = MIMEMultipart('alternative')
message['Subject'] = subject
message['From'] = userName
message['To'] = receiverMails
message['To'] = receiver
# Create the plain-text and HTML version of your message
text = subject
......@@ -42,9 +53,3 @@ class MailHandler:
# The email client will try to render the last part first
message.attach(part1)
message.attach(part2)
# Create secure connection with server and send email
context = ssl.create_default_context()
with smtplib.SMTP_SSL(host, port, context=context) as server:
server.login(userName, password)
server.sendmail(userName, receiverMails, message.as_string())
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment