From 0078fe705709cc7b9f1c0a59c261b9f67d4d70c2 Mon Sep 17 00:00:00 2001 From: Cameron Hyde Date: Fri, 5 Jan 2024 08:32:33 +1000 Subject: [PATCH 1/4] Reply-to user email on tool error email --- lib/galaxy/config/schemas/config_schema.yml | 8 ++++++++ lib/galaxy/tools/errors.py | 3 ++- lib/galaxy/util/__init__.py | 10 ++++++++-- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/lib/galaxy/config/schemas/config_schema.yml b/lib/galaxy/config/schemas/config_schema.yml index e66696aec4aa..fc2918f2b3af 100644 --- a/lib/galaxy/config/schemas/config_schema.yml +++ b/lib/galaxy/config/schemas/config_schema.yml @@ -1159,6 +1159,14 @@ mapping: set. Also this email is shown as a contact to user in case of Galaxy misconfiguration and other events user may encounter. + error_email_reply_to_user: + type: bool + required: false + desc: | + When sending email reports for tool errors, include the user's email address + in the Reply-to SMTP header (used by some ticketing systems to identify the + appropriate response address). + email_from: type: str required: false diff --git a/lib/galaxy/tools/errors.py b/lib/galaxy/tools/errors.py index da55ef82eaed..deddd5bb72f2 100644 --- a/lib/galaxy/tools/errors.py +++ b/lib/galaxy/tools/errors.py @@ -253,6 +253,7 @@ def _send_report(self, user, email=None, message=None, **kwd): except Exception: pass + reply_to = user.email if self.app.config.error_email_reply_to_user else None return util.send_mail( - self.app.config.email_from, to, subject, self.report, self.app.config, html=self.html_report + self.app.config.email_from, to, subject, self.report, self.app.config, html=self.html_report, reply_to=reply_to ) diff --git a/lib/galaxy/util/__init__.py b/lib/galaxy/util/__init__.py index 20c113861ae1..f0f9922ca172 100644 --- a/lib/galaxy/util/__init__.py +++ b/lib/galaxy/util/__init__.py @@ -1506,7 +1506,7 @@ def size_to_bytes(size): raise ValueError(f"Unknown multiplier '{multiple}' in '{size}'") -def send_mail(frm, to, subject, body, config, html=None): +def send_mail(frm, to, subject, body, config, html=None, reply_to=None): """ Sends an email. @@ -1527,7 +1527,10 @@ def send_mail(frm, to, subject, body, config, html=None): :type html: str :param html: Alternative HTML representation of the body content. If - provided will convert the message to a MIMEMultipart. (Default 'None') + provided will convert the message to a MIMEMultipart. (Default None) + + :type reply_to: str + :param reply_to: Reply-to address (Default None) """ to = listify(to) @@ -1551,6 +1554,9 @@ def send_mail(frm, to, subject, body, config, html=None): msg.attach(mp_text) msg.attach(mp_html) + if reply_to: + msg["Reply-To"] = reply_to + smtp_ssl = asbool(getattr(config, "smtp_ssl", False)) if smtp_ssl: s = smtplib.SMTP_SSL(config.smtp_server) From ee152e5293c1f112e56bc190d8c43aea9ca9b0bf Mon Sep 17 00:00:00 2001 From: Cameron Hyde Date: Fri, 5 Jan 2024 09:03:16 +1000 Subject: [PATCH 2/4] Config rebuild --- doc/source/admin/galaxy_options.rst | 12 ++++++++++++ lib/galaxy/config/sample/galaxy.yml.sample | 5 +++++ 2 files changed, 17 insertions(+) diff --git a/doc/source/admin/galaxy_options.rst b/doc/source/admin/galaxy_options.rst index 01da0516fecd..12f05be9b0f9 100644 --- a/doc/source/admin/galaxy_options.rst +++ b/doc/source/admin/galaxy_options.rst @@ -1620,6 +1620,18 @@ :Type: str +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +``error_email_reply_to_user`` +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +:Description: + When sending email reports for tool errors, include the user's + email address in the Reply-to SMTP header (used by some ticketing + systems to identify the appropriate response address). +:Default: ``None`` +:Type: bool + + ~~~~~~~~~~~~~~ ``email_from`` ~~~~~~~~~~~~~~ diff --git a/lib/galaxy/config/sample/galaxy.yml.sample b/lib/galaxy/config/sample/galaxy.yml.sample index 4e807958e685..d2585104bbcd 100644 --- a/lib/galaxy/config/sample/galaxy.yml.sample +++ b/lib/galaxy/config/sample/galaxy.yml.sample @@ -1105,6 +1105,11 @@ galaxy: # user may encounter. #error_email_to: null + # When sending email reports for tool errors, include the user's email + # address in the Reply-to SMTP header (used by some ticketing systems + # to identify the appropriate response address). + #error_email_reply_to_user: false + # Email address to use in the 'From' field when sending emails for # account activations, workflow step notifications, password resets, # and tool error reports. We recommend using a string in the From b2e1402a97d24d3cb9516d02939796598164fb7a Mon Sep 17 00:00:00 2001 From: Cameron Hyde Date: Fri, 5 Jan 2024 09:21:54 +1000 Subject: [PATCH 3/4] Lint and format --- lib/galaxy/tools/errors.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/galaxy/tools/errors.py b/lib/galaxy/tools/errors.py index deddd5bb72f2..d437e5361d82 100644 --- a/lib/galaxy/tools/errors.py +++ b/lib/galaxy/tools/errors.py @@ -255,5 +255,11 @@ def _send_report(self, user, email=None, message=None, **kwd): reply_to = user.email if self.app.config.error_email_reply_to_user else None return util.send_mail( - self.app.config.email_from, to, subject, self.report, self.app.config, html=self.html_report, reply_to=reply_to + self.app.config.email_from, + to, + subject, + self.report, + self.app.config, + html=self.html_report, + reply_to=reply_to, ) From 5f6fc7126e67f93526965a70d5228cb303707904 Mon Sep 17 00:00:00 2001 From: Cameron Hyde Date: Wed, 10 Jan 2024 04:55:48 +1000 Subject: [PATCH 4/4] Remove Reply-to as a configurable --- doc/source/admin/galaxy_options.rst | 12 ------------ lib/galaxy/config/sample/galaxy.yml.sample | 5 ----- lib/galaxy/config/schemas/config_schema.yml | 8 -------- lib/galaxy/tools/errors.py | 2 +- lib/galaxy/util/__init__.py | 6 +++--- 5 files changed, 4 insertions(+), 29 deletions(-) diff --git a/doc/source/admin/galaxy_options.rst b/doc/source/admin/galaxy_options.rst index 12f05be9b0f9..01da0516fecd 100644 --- a/doc/source/admin/galaxy_options.rst +++ b/doc/source/admin/galaxy_options.rst @@ -1620,18 +1620,6 @@ :Type: str -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -``error_email_reply_to_user`` -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -:Description: - When sending email reports for tool errors, include the user's - email address in the Reply-to SMTP header (used by some ticketing - systems to identify the appropriate response address). -:Default: ``None`` -:Type: bool - - ~~~~~~~~~~~~~~ ``email_from`` ~~~~~~~~~~~~~~ diff --git a/lib/galaxy/config/sample/galaxy.yml.sample b/lib/galaxy/config/sample/galaxy.yml.sample index d2585104bbcd..4e807958e685 100644 --- a/lib/galaxy/config/sample/galaxy.yml.sample +++ b/lib/galaxy/config/sample/galaxy.yml.sample @@ -1105,11 +1105,6 @@ galaxy: # user may encounter. #error_email_to: null - # When sending email reports for tool errors, include the user's email - # address in the Reply-to SMTP header (used by some ticketing systems - # to identify the appropriate response address). - #error_email_reply_to_user: false - # Email address to use in the 'From' field when sending emails for # account activations, workflow step notifications, password resets, # and tool error reports. We recommend using a string in the diff --git a/lib/galaxy/config/schemas/config_schema.yml b/lib/galaxy/config/schemas/config_schema.yml index fc2918f2b3af..e66696aec4aa 100644 --- a/lib/galaxy/config/schemas/config_schema.yml +++ b/lib/galaxy/config/schemas/config_schema.yml @@ -1159,14 +1159,6 @@ mapping: set. Also this email is shown as a contact to user in case of Galaxy misconfiguration and other events user may encounter. - error_email_reply_to_user: - type: bool - required: false - desc: | - When sending email reports for tool errors, include the user's email address - in the Reply-to SMTP header (used by some ticketing systems to identify the - appropriate response address). - email_from: type: str required: false diff --git a/lib/galaxy/tools/errors.py b/lib/galaxy/tools/errors.py index d437e5361d82..38ebccf5e3f2 100644 --- a/lib/galaxy/tools/errors.py +++ b/lib/galaxy/tools/errors.py @@ -253,7 +253,7 @@ def _send_report(self, user, email=None, message=None, **kwd): except Exception: pass - reply_to = user.email if self.app.config.error_email_reply_to_user else None + reply_to = user.email if user else None return util.send_mail( self.app.config.email_from, to, diff --git a/lib/galaxy/util/__init__.py b/lib/galaxy/util/__init__.py index f0f9922ca172..0f954b3b700a 100644 --- a/lib/galaxy/util/__init__.py +++ b/lib/galaxy/util/__init__.py @@ -1543,6 +1543,9 @@ def send_mail(frm, to, subject, body, config, html=None, reply_to=None): msg["From"] = frm msg["Subject"] = subject + if reply_to: + msg["Reply-To"] = reply_to + if config.smtp_server is None: log.error("Mail is not configured for this Galaxy instance.") log.info(msg) @@ -1554,9 +1557,6 @@ def send_mail(frm, to, subject, body, config, html=None, reply_to=None): msg.attach(mp_text) msg.attach(mp_html) - if reply_to: - msg["Reply-To"] = reply_to - smtp_ssl = asbool(getattr(config, "smtp_ssl", False)) if smtp_ssl: s = smtplib.SMTP_SSL(config.smtp_server)