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):
......@@ -436,15 +436,16 @@ 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
......@@ -459,9 +460,14 @@ class Workflow(threading.Thread):
msg['To'] = you
# Send the message via our own SMTP server, but don't include the
# envelope header.
s = smtplib.SMTP(smtps)
s = smtplib.SMTP(smtps, smtpp)
s.login(me, fromp)
s.sendmail(me, [you], msg.as_string())
logging.getLogger("wf." + str("Impossible to connect to smtp server '" + smtps + "'")
def get_parameters_per_groups(self):
name = self.get_name()
Supports Markdown
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