Skip to content

Commit

Permalink
Merge 38a29c3 into 88b954a
Browse files Browse the repository at this point in the history
  • Loading branch information
mvidalgarcia committed Apr 29, 2020
2 parents 88b954a + 38a29c3 commit 6d6417e
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
40 changes: 40 additions & 0 deletions reana_commons/mail.py
@@ -0,0 +1,40 @@
# -*- coding: utf-8 -*-
#
# This file is part of REANA.
# Copyright (C) 2020 CERN.
#
# REANA is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.
"""REANA-Commons email util."""

import logging
import os
import smtplib
import ssl

# Email configuration
REANA_SMTP_SERVER = os.getenv('REANA_SMTP_SERVER')
REANA_SMTP_PORT = os.getenv('REANA_SMTP_PORT')
REANA_EMAIL_LOGIN = os.getenv('REANA_EMAIL_LOGIN')
REANA_EMAIL_SENDER = os.getenv('REANA_EMAIL_SENDER')
REANA_EMAIL_PASSWORD = os.getenv('REANA_EMAIL_PASSWORD')


def send_email(receiver_email, subject, body, login_email=REANA_EMAIL_LOGIN,
sender_email=REANA_EMAIL_SENDER):
"""Send emails from REANA platform."""
message = """\
Subject: {subject}
{body}""".format(subject=subject, body=body)

if os.environ['FLASK_ENV'] == 'development':
logging.info('Email sent, login: {}, sender: {}, receiver: {}'
.format(login_email, sender_email, receiver_email))
logging.info('Body:\n{}'.format(message))
else:
context = ssl.create_default_context()
with smtplib.SMTP(REANA_SMTP_SERVER, REANA_SMTP_PORT) as server:
server.starttls(context=context)
server.login(login_email, REANA_EMAIL_PASSWORD)
server.sendmail(sender_email, receiver_email, message)
2 changes: 1 addition & 1 deletion reana_commons/version.py
Expand Up @@ -14,4 +14,4 @@

from __future__ import absolute_import, print_function

__version__ = "0.7.0.dev20200417"
__version__ = "0.7.0.dev20200429"

0 comments on commit 6d6417e

Please sign in to comment.