Implement reply-to setting

This commit is contained in:
Seb 2020-05-19 11:29:14 +10:00
parent 14f21f2c31
commit df5b68e144
3 changed files with 18 additions and 8 deletions

View File

@ -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
return settings.DEFAULT_FROM_EMAIL
@property
def reply_to(self):
return getattr(settings, 'BIRDSONG_REPLY_TO', self.from_email)

View File

@ -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

View File

@ -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)