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

Commit a952d27

Browse files
committed
Add a return address for bounced emails
1 parent 44d97af commit a952d27

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

dmutils/email.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ def send_email(to_email_addresses, email_body, subject, from_email, from_name, r
5353
}
5454
if 'DM_EMAIL_BCC_ADDRESS' in current_app.config:
5555
destination_addresses['BccAddresses'] = [current_app.config['DM_EMAIL_BCC_ADDRESS']]
56-
56+
if 'DM_EMAIL_RETURN_ADDRESS' in current_app.config:
57+
return_address = current_app.config['DM_EMAIL_RETURN_ADDRESS']
5758
result = email_client.send_email(
5859
Source=u"{} <{}>".format(from_name, from_email),
5960
Destination=destination_addresses,
@@ -69,6 +70,7 @@ def send_email(to_email_addresses, email_body, subject, from_email, from_name, r
6970
}
7071
}
7172
},
73+
ReturnPath=return_address or reply_to or from_email,
7274
ReplyToAddresses=[reply_to or from_email],
7375
)
7476
except botocore.exceptions.ClientError as e:

tests/test_email.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
TEST_SECRET_KEY = 'TestKeyTestKeyTestKeyTestKeyTestKeyTestKeyX='
1818
TEST_ARCHIVE_ADDRESS = '[email protected]'
19+
TEST_RETURN_ADDRESS = '[email protected]'
1920

2021

2122
@pytest.yield_fixture
@@ -33,6 +34,7 @@ def email_app(app):
3334
app.config['SECRET_KEY'] = TEST_SECRET_KEY
3435
app.config['RESET_PASSWORD_SALT'] = 'PassSalt'
3536
app.config['DM_EMAIL_BCC_ADDRESS'] = TEST_ARCHIVE_ADDRESS
37+
app.config['DM_EMAIL_RETURN_ADDRESS'] = TEST_RETURN_ADDRESS
3638
yield app
3739

3840

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

5760

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

9397

0 commit comments

Comments
 (0)