SES: Fix sending email when use verify_email_address (#3242)

This commit is contained in:
Kamil Mańkowski 2020-08-25 14:51:58 +02:00 committed by GitHub
parent 8a551a9754
commit 47a227921d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 0 deletions

View File

@ -103,6 +103,8 @@ class SESBackend(BaseBackend):
_, address = parseaddr(source)
if address in self.addresses:
return True
if address in self.email_addresses:
return True
user, host = address.split("@", 1)
return host in self.domains

View File

@ -84,6 +84,35 @@ def test_send_email():
sent_count.should.equal(3)
@mock_ses
def test_send_email_when_verify_source():
conn = boto3.client("ses", region_name="us-east-1")
kwargs = dict(
Destination={"ToAddresses": ["test_to@example.com"],},
Message={
"Subject": {"Data": "test subject"},
"Body": {"Text": {"Data": "test body"}},
},
)
conn.send_email.when.called_with(
Source="verify_email_address@example.com", **kwargs
).should.throw(ClientError)
conn.verify_email_address(EmailAddress="verify_email_address@example.com")
conn.send_email(Source="verify_email_address@example.com", **kwargs)
conn.send_email.when.called_with(
Source="verify_email_identity@example.com", **kwargs
).should.throw(ClientError)
conn.verify_email_identity(EmailAddress="verify_email_identity@example.com")
conn.send_email(Source="verify_email_identity@example.com", **kwargs)
send_quota = conn.get_send_quota()
sent_count = int(send_quota["SentLast24Hours"])
sent_count.should.equal(2)
@mock_ses
def test_send_templated_email():
conn = boto3.client("ses", region_name="us-east-1")