diff --git a/birdsong/backends/__init__.py b/birdsong/backends/__init__.py index 5e56fd8..9c2279f 100644 --- a/birdsong/backends/__init__.py +++ b/birdsong/backends/__init__.py @@ -8,4 +8,8 @@ class BaseEmailBackend: def from_email(self): if hasattr(settings, 'BIRDSONG_FROM_EMAIL'): return settings.BIRDSONG_FROM_EMAIL - return settings.DEFAULT_FROM_EMAIL \ No newline at end of file + return settings.DEFAULT_FROM_EMAIL + + @property + def reply_to(self): + return getattr(settings, 'BIRDSONG_REPLY_TO', self.from_email) \ No newline at end of file diff --git a/birdsong/backends/smtp.py b/birdsong/backends/smtp.py index ac33f28..f86c034 100644 --- a/birdsong/backends/smtp.py +++ b/birdsong/backends/smtp.py @@ -17,10 +17,16 @@ class SMTPEmailBackend(BaseEmailBackend): campaign.get_template(request), campaign.get_context(request, contact), ) - messages.append((subject, content, self.from_email, [contact.email])) + messages.append({ + 'subject': subject, + 'body': content, + 'from_email': self.from_email, + 'to': [contact.email], + 'reply_to': [self.reply_to], + }) try: - send_mass_html_mail(tuple(messages)) + send_mass_html_mail(messages) success = True except SMTPException as e: success = False diff --git a/birdsong/utils.py b/birdsong/utils.py index 57a38e7..b3b5164 100644 --- a/birdsong/utils.py +++ b/birdsong/utils.py @@ -1,7 +1,7 @@ from django.core.mail import EmailMultiAlternatives, get_connection -def send_mass_html_mail(datatuple, fail_silently=False, auth_user=None, +def send_mass_html_mail(email_data, fail_silently=False, auth_user=None, auth_password=None, connection=None): """ Modified version of send_mass_mail to allow html email @@ -12,10 +12,10 @@ def send_mass_html_mail(datatuple, fail_silently=False, auth_user=None, fail_silently=fail_silently, ) - def _email_from_tuple(tuple): - msg = EmailMultiAlternatives(*tuple, connection=connection) - msg.attach_alternative(tuple[1], "text/html") + def _email_from_dict(data): + msg = EmailMultiAlternatives(connection=connection, **data) + msg.attach_alternative(data['body'], "text/html") return msg - messages = [_email_from_tuple(m) for m in datatuple] + messages = [_email_from_dict(d) for d in email_data] return connection.send_messages(messages)