Implement reply-to setting
This commit is contained in:
parent
14f21f2c31
commit
df5b68e144
|
@ -8,4 +8,8 @@ class BaseEmailBackend:
|
||||||
def from_email(self):
|
def from_email(self):
|
||||||
if hasattr(settings, 'BIRDSONG_FROM_EMAIL'):
|
if hasattr(settings, 'BIRDSONG_FROM_EMAIL'):
|
||||||
return 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)
|
|
@ -17,10 +17,16 @@ class SMTPEmailBackend(BaseEmailBackend):
|
||||||
campaign.get_template(request),
|
campaign.get_template(request),
|
||||||
campaign.get_context(request, contact),
|
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:
|
try:
|
||||||
send_mass_html_mail(tuple(messages))
|
send_mass_html_mail(messages)
|
||||||
success = True
|
success = True
|
||||||
except SMTPException as e:
|
except SMTPException as e:
|
||||||
success = False
|
success = False
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
from django.core.mail import EmailMultiAlternatives, get_connection
|
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):
|
auth_password=None, connection=None):
|
||||||
"""
|
"""
|
||||||
Modified version of send_mass_mail to allow html email
|
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,
|
fail_silently=fail_silently,
|
||||||
)
|
)
|
||||||
|
|
||||||
def _email_from_tuple(tuple):
|
def _email_from_dict(data):
|
||||||
msg = EmailMultiAlternatives(*tuple, connection=connection)
|
msg = EmailMultiAlternatives(connection=connection, **data)
|
||||||
msg.attach_alternative(tuple[1], "text/html")
|
msg.attach_alternative(data['body'], "text/html")
|
||||||
return msg
|
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)
|
return connection.send_messages(messages)
|
||||||
|
|
Loading…
Reference in New Issue