Skip to content

Commit

Permalink
Merge pull request #54 from novapost/54-add_no_reply_address
Browse files Browse the repository at this point in the history
Add a no_reply address.
  • Loading branch information
yakuru committed Jan 28, 2015
2 parents 74c0abe + 6dfbc08 commit d3c46e5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
9 changes: 6 additions & 3 deletions mail_factory/mails.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,12 @@ def create_email_msg(self, emails, attachments=None, from_email=None,
body = h.handle(html_content)

if headers is None:
headers = {'Reply-To': getattr(settings,
"SUPPORT_EMAIL",
settings.DEFAULT_FROM_EMAIL)}
reply_to = getattr(settings, "NO_REPLY_EMAIL", None)
if not reply_to:
reply_to = getattr(settings, "SUPPORT_EMAIL",
settings.DEFAULT_FROM_EMAIL)

headers = {'Reply-To': reply_to}

msg = message_class(subject, body, from_email, emails, headers=headers)
if html_content:
Expand Down
19 changes: 19 additions & 0 deletions mail_factory/tests/test_mails.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,22 @@ class TestMail(BaseMail):
TestMail().mail_admins()
self.assertEqual(len(mail.outbox), before + 1)
self.assertEqual(mail.outbox[-1].to, ['some_admin@example.com'])

def test_no_reply(self):
class TestMail(BaseMail):
params = []
template_name = 'test'

test_mail = TestMail()
msg = test_mail.create_email_msg([])

self.assertIn('Reply-To', msg.extra_headers)
self.assertEquals(msg.extra_headers['Reply-To'],
settings.DEFAULT_FROM_EMAIL)

settings.NO_REPLY_EMAIL = 'no-reply@example.com'
msg = test_mail.create_email_msg([])

self.assertIn('Reply-To', msg.extra_headers)
self.assertEquals(msg.extra_headers['Reply-To'],
settings.NO_REPLY_EMAIL)

0 comments on commit d3c46e5

Please sign in to comment.