2020-07-01 19:30:12 +00:00
|
|
|
# Copyright (C) 2020 by Thomas Lindner <tom@dl6tom.de>
|
|
|
|
# Copyright (C) 2020 by Cathy Hu <cathy.hu@fau.de>
|
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: 0BSD
|
|
|
|
|
2020-07-11 10:54:07 +00:00
|
|
|
""" E-Mail handling. """
|
|
|
|
|
2020-07-01 19:30:12 +00:00
|
|
|
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=''):
|
2020-09-04 23:39:24 +00:00
|
|
|
"""E-Mail sender.
|
2020-07-11 10:54:07 +00:00
|
|
|
|
|
|
|
Sends an E-Mail to a specified recipient with a body
|
|
|
|
|
|
|
|
Example:
|
|
|
|
```
|
|
|
|
from kibicara import email
|
2020-07-17 17:59:25 +00:00
|
|
|
email.send_email('abc@de.fg', 'Email subject', body='Hi this is a mail body.')
|
2020-07-11 10:54:07 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
Args:
|
|
|
|
to (str): Recipients' e-mail address
|
|
|
|
subject (str): The subject of the e-mail
|
|
|
|
sender (str): optional, Sender of the e-mail
|
|
|
|
body (str): The body of the e-mail
|
|
|
|
"""
|
2020-07-01 19:30:12 +00:00
|
|
|
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)
|