Commit b0792588 authored by Jerome Mariette's avatar Jerome Mariette
Browse files

make jflow able to send emails

parent 7bd23523
......@@ -33,7 +33,9 @@ server_socket_port = 8080
# if you want an email to be sent at the end of the workflow execution
# set the smtp_server and the from_address values
smtp_server =
smtp_port =
from_address =
from_password =
# uncomment and set if you want to use these values for all the workflow
# these variables can be overloaded within the workflow implementation by
# using self.set_to_address("address"), self.set_subject("subject"),
......
......@@ -92,15 +92,19 @@ class JFlowConfigReader(object):
def get_email_options(self):
try: smtps = self.reader.get("email", "smtp_server")
except: smtps = None
try: smtpp = self.reader.get("email", "smtp_port")
except: smtpp = None
try: froma = self.reader.get("email", "from_address")
except: froma = None
try: fromp = self.reader.get("email", "from_password")
except: fromp = None
try: toa = self.reader.get("email", "to_address")
except: toa = None
try: subject = self.reader.get("email", "subject")
except: subject = None
try: message = self.reader.get("email", "message")
except: message = None
return [smtps, froma, toa, subject, message]
return [smtps, smtpp, froma, fromp, toa, subject, message]
def get_component_batch_options(self, component_class):
try:
......
......@@ -436,33 +436,39 @@ class Workflow(threading.Thread):
import smtplib
from email.mime.text import MIMEText
smtps, froma, toa, subject, message = self.jflow_config_reader.get_email_options()
smtps, smtpp, froma, fromp, toa, subject, message = self.jflow_config_reader.get_email_options()
if self.__to_address: toa = self.__to_address
if self.__subject: subject = self.__subject
if self.__message: message = self.__message
if smtps and froma:
if smtps and smtpp and froma and fromp:
if not toa: toa = froma
if validate_email(froma) and validate_email(toa):
# Open a plain text file for reading. For this example, assume that
# the text file contains only ASCII characters.
# Create a text/plain message
if not message:
message = self.get_status_under_text_format(True, True)
msg = MIMEText(message)
me = froma
you = toa
if not subject: subject = "JFlow - Workflow #" + str(self.id) + " is " + self.status
msg['Subject'] = subject
msg['From'] = me
msg['To'] = you
# Send the message via our own SMTP server, but don't include the
# envelope header.
s = smtplib.SMTP(smtps)
s.sendmail(me, [you], msg.as_string())
s.quit()
try:
# Open a plain text file for reading. For this example, assume that
# the text file contains only ASCII characters.
# Create a text/plain message
if not message:
message = self.get_status_under_text_format(True, True)
msg = MIMEText(message)
me = froma
you = toa
if not subject: subject = "JFlow - Workflow #" + str(self.id) + " is " + self.status
msg['Subject'] = subject
msg['From'] = me
msg['To'] = you
# Send the message via our own SMTP server, but don't include the
# envelope header.
s = smtplib.SMTP(smtps, smtpp)
s.ehlo()
s.starttls()
s.login(me, fromp)
s.sendmail(me, [you], msg.as_string())
s.close()
except:
logging.getLogger("wf." + str(self.id)).debug("Impossible to connect to smtp server '" + smtps + "'")
def get_parameters_per_groups(self):
name = self.get_name()
description = self.get_description()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment