diff --git a/re2oapi/__init__.py b/re2oapi/__init__.py index 5939662..a6ea559 100644 --- a/re2oapi/__init__.py +++ b/re2oapi/__init__.py @@ -1,4 +1,4 @@ -from .client import Re2oAPIClient +from .client import ApiSendMail, Re2oAPIClient from . import exceptions -__all__ = ['Re2oAPIClient', 'exceptions'] +__all__ = ['Re2oAPIClient', 'ApiSendMail', 'exceptions'] diff --git a/re2oapi/client.py b/re2oapi/client.py index 5adb1bc..b654331 100644 --- a/re2oapi/client.py +++ b/re2oapi/client.py @@ -5,9 +5,11 @@ from pathlib import Path import stat import json import requests +import smtplib +from email.mime.multipart import MIMEMultipart +from email.mime.text import MIMEText from requests.exceptions import HTTPError -from . import endpoints from . import exceptions # Number of seconds before expiration where renewing the token is done @@ -556,3 +558,24 @@ class Re2oAPIClient: self.log.debug("Viewing object under '{}' successful" .format(endpoint)) return ret + + +class ApiSendMail: + """Basic api for sending mails""" + def __init__(self, server, port, starttls=False): + """Give here the server, the port and tls or not""" + self.connection = smtplib.SMTP(server, port) + if starttls: + self.connection.starttls() + + def send_mail(self, email_from, email_to, subject, body, mode='html'): + """Sending mail from from, to, subject and body""" + self.msg = MIMEMultipart() + self.msg['From'] = email_from + self.msg['To'] = email_to + self.msg['Subject'] = subject + self.msg.attach(MIMEText(body, mode)) + self.connection.sendmail(email_from, email_to, self.msg.as_string()) + + def close(self): + self.connection.quit()