From b769ee48865f781b7c9cfb6e68e84a72de00a32c Mon Sep 17 00:00:00 2001 From: Martijn Vermaat <martijn@vermaat.name> Date: Mon, 9 Nov 2015 11:27:08 +0100 Subject: [PATCH] Customizable sender address in batch job notifications This address is set with the new `BATCH_NOTIFICATION_EMAIL` config setting and defaults to the value of `EMAIL`. --- doc/config.rst | 11 ++++++++--- mutalyzer/Scheduler.py | 5 +++-- mutalyzer/config/default_settings.py | 9 ++++++--- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/doc/config.rst b/doc/config.rst index 1df8eea5..198356f1 100644 --- a/doc/config.rst +++ b/doc/config.rst @@ -58,12 +58,17 @@ not set by default. .. _config-email: EMAIL - The email address used in contact information on the website, as sender in - batch job notifications, and in communication with the NCBI webservices - using Entrez. + The email address used in contact information on the website and sent with + NCBI Entrez calls. `Default value:` ``mutalyzer@humgen.nl`` +BATCH_NOTIFICATION_EMAIL + The email address used as sender in batch job notifications. If set to + `None`, the value of :ref:`EMAIL <config-email>` will be used. + + `Default value:` `None` + .. _config-debug: DEBUG diff --git a/mutalyzer/Scheduler.py b/mutalyzer/Scheduler.py index 96db9f07..81d952e4 100644 --- a/mutalyzer/Scheduler.py +++ b/mutalyzer/Scheduler.py @@ -106,6 +106,7 @@ class Scheduler() : #TODO: Handle Connection errors in a try, except clause #Expected errors: socket.error + from_address = settings.BATCH_NOTIFICATION_EMAIL or settings.EMAIL download_url = website.url_for('batch_job_result', result_id=result_id) @@ -123,7 +124,7 @@ With kind regards, Mutalyzer batch scheduler""" % download_url) message["Subject"] = "Result of your Mutalyzer batch job" - message["From"] = settings.EMAIL + message["From"] = from_address message["To"] = mailTo try: @@ -138,7 +139,7 @@ Mutalyzer batch scheduler""" % download_url) return try: - smtpInstance.sendmail(settings.EMAIL, mailTo, message.as_string()) + smtpInstance.sendmail(from_address, mailTo, message.as_string()) except smtplib.SMTPRecipientsRefused as e: for address, (code, error) in e.recipients.items(): print 'Could not send email to %s: (%s) %s' % (address, diff --git a/mutalyzer/config/default_settings.py b/mutalyzer/config/default_settings.py index 4007fd0a..5f3e6e05 100644 --- a/mutalyzer/config/default_settings.py +++ b/mutalyzer/config/default_settings.py @@ -13,11 +13,14 @@ DEBUG = False # We are running unit tests. TESTING = False -# This address is used in contact information on the website, as sender in -# batch job notifications, and with retrieval of records at the NCBI using -# Entrez. +# This email address is used in contact information on the website and sent +# with NCBI Entrez calls. EMAIL = 'mutalyzer@humgen.nl' +# This email address is used as sender in batch job notifications. If `None`, +# the value of `EMAIL` will be used. +BATCH_NOTIFICATION_EMAIL = None + # The cache directory. Used to store uploaded and downloaded files (e.g., # reference files from NCBI or user) and batch job results. CACHE_DIR = '/tmp' -- GitLab