Skip to content

Commit

Permalink
Adds optional reply-to email reporter config param
Browse files Browse the repository at this point in the history
  • Loading branch information
trevorshannon committed Feb 5, 2024
1 parent e342af9 commit 3af5d98
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
6 changes: 4 additions & 2 deletions lib/urlwatch/mailer.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,23 @@ class Mailer(object):
def send(self, msg):
raise NotImplementedError

def msg_plain(self, from_email, to_email, subject, body):
def msg_plain(self, from_email, to_email, reply_to_email, subject, body):
msg = email.mime.text.MIMEText(body, 'plain', 'utf-8')
msg['Subject'] = subject
msg['From'] = from_email
msg['To'] = to_email
msg['Date'] = email.utils.formatdate()
msg['Reply-To'] = reply_to_email

return msg

def msg_html(self, from_email, to_email, subject, body_text, body_html):
def msg_html(self, from_email, to_email, reply_to_email, subject, body_text, body_html):
msg = email.mime.multipart.MIMEMultipart('alternative')
msg['Subject'] = subject
msg['From'] = from_email
msg['To'] = to_email
msg['Date'] = email.utils.formatdate()
msg['Reply-To'] = reply_to_email

msg.attach(email.mime.text.MIMEText(body_text, 'plain', 'utf-8'))
msg.attach(email.mime.text.MIMEText(body_html, 'html', 'utf-8'))
Expand Down
5 changes: 3 additions & 2 deletions lib/urlwatch/reporters.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,12 +455,13 @@ def submit(self):
else:
logger.error('Invalid entry for method {method}'.format(method=self.config['method']))

reply_to = self.config.get('reply_to', self.config['from'])
if self.config['html']:
body_html = '\n'.join(self.convert(HtmlReporter).submit())

msg = mailer.msg_html(self.config['from'], self.config['to'], subject, body_text, body_html)
msg = mailer.msg_html(self.config['from'], self.config['to'], reply_to, subject, body_text, body_html)
else:
msg = mailer.msg_plain(self.config['from'], self.config['to'], subject, body_text)
msg = mailer.msg_plain(self.config['from'], self.config['to'], reply_to, subject, body_text)

mailer.send(msg)

Expand Down

0 comments on commit 3af5d98

Please sign in to comment.