Skip to content
This repository has been archived by the owner on Jul 7, 2022. It is now read-only.

Commit

Permalink
Merge pull request #46 from AusDTO/feature/return-address-for-emails
Browse files Browse the repository at this point in the history
Add a return address for bounced emails
  • Loading branch information
maxious authored Oct 13, 2016
2 parents 44d97af + a952d27 commit c49ec75
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 3 additions & 1 deletion dmutils/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ def send_email(to_email_addresses, email_body, subject, from_email, from_name, r
}
if 'DM_EMAIL_BCC_ADDRESS' in current_app.config:
destination_addresses['BccAddresses'] = [current_app.config['DM_EMAIL_BCC_ADDRESS']]

if 'DM_EMAIL_RETURN_ADDRESS' in current_app.config:
return_address = current_app.config['DM_EMAIL_RETURN_ADDRESS']
result = email_client.send_email(
Source=u"{} <{}>".format(from_name, from_email),
Destination=destination_addresses,
Expand All @@ -69,6 +70,7 @@ def send_email(to_email_addresses, email_body, subject, from_email, from_name, r
}
}
},
ReturnPath=return_address or reply_to or from_email,
ReplyToAddresses=[reply_to or from_email],
)
except botocore.exceptions.ClientError as e:
Expand Down
8 changes: 6 additions & 2 deletions tests/test_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

TEST_SECRET_KEY = 'TestKeyTestKeyTestKeyTestKeyTestKeyTestKeyX='
TEST_ARCHIVE_ADDRESS = '[email protected]'
TEST_RETURN_ADDRESS = '[email protected]'


@pytest.yield_fixture
Expand All @@ -33,6 +34,7 @@ def email_app(app):
app.config['SECRET_KEY'] = TEST_SECRET_KEY
app.config['RESET_PASSWORD_SALT'] = 'PassSalt'
app.config['DM_EMAIL_BCC_ADDRESS'] = TEST_ARCHIVE_ADDRESS
app.config['DM_EMAIL_RETURN_ADDRESS'] = TEST_RETURN_ADDRESS
yield app


Expand All @@ -51,7 +53,8 @@ def test_calls_send_email_with_correct_params(email_app, email_client):
Message={'Body': {'Html': {'Charset': 'UTF-8', 'Data': 'body'}},
'Subject': {'Charset': 'UTF-8', 'Data': 'subject'}},
Destination={'ToAddresses': ['email_address'], 'BccAddresses': [TEST_ARCHIVE_ADDRESS]},
Source=u'from_name <from_email>'
Source=u'from_name <from_email>',
ReturnPath=TEST_RETURN_ADDRESS
)


Expand Down Expand Up @@ -87,7 +90,8 @@ def test_calls_send_email_with_alternative_reply_to(email_app, email_client):
Message={'Body': {'Html': {'Charset': 'UTF-8', 'Data': 'body'}},
'Subject': {'Charset': 'UTF-8', 'Data': 'subject'}},
Destination={'ToAddresses': ['email_address'], 'BccAddresses': [TEST_ARCHIVE_ADDRESS]},
Source=u'from_name <from_email>'
Source=u'from_name <from_email>',
ReturnPath=TEST_RETURN_ADDRESS
)


Expand Down

0 comments on commit c49ec75

Please sign in to comment.