From 647fe0ef364cfd02c8f8c48899470a8faed88b8a Mon Sep 17 00:00:00 2001 From: Cathy Hu Date: Wed, 1 Jul 2020 21:30:12 +0200 Subject: [PATCH] [core] Add send process for notification/confirm email --- kibicara/email.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 kibicara/email.py diff --git a/kibicara/email.py b/kibicara/email.py new file mode 100644 index 0000000..8ab2d5d --- /dev/null +++ b/kibicara/email.py @@ -0,0 +1,24 @@ +# Copyright (C) 2020 by Thomas Lindner +# Copyright (C) 2020 by Cathy Hu +# +# SPDX-License-Identifier: 0BSD + +from email.mime.text import MIMEText +from email.mime.multipart import MIMEMultipart +from logging import getLogger +from smtplib import SMTP +from socket import getfqdn + + +logger = getLogger(__name__) + + +def send_email(to, subject, sender='kibicara', body=''): + msg = MIMEMultipart() + msg['From'] = 'Kibicara <%s@%s>' % (sender, getfqdn()) + msg['To'] = to + msg['Subject'] = '[Kibicara] %s' % subject + msg.attach(MIMEText(body)) + + with SMTP('localhost') as smtp: + smtp.send_message(msg)