SES: set_identity_mail_from_domain() - the Identity can be an email (#6755)

This commit is contained in:
Bert Blommers 2023-09-01 21:56:47 +00:00 committed by GitHub
parent c59fee5d35
commit 5af4421524
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 4 deletions

View File

@ -165,7 +165,7 @@ class SESBackend(BaseBackend):
return True
if address in self.email_addresses:
return True
_, host = address.split("@", 1)
host = address.split("@", 1)[-1]
return host in self.domains
def verify_email_identity(self, address: str) -> None:
@ -572,17 +572,17 @@ class SESBackend(BaseBackend):
mail_from_domain: Optional[str] = None,
behavior_on_mx_failure: Optional[str] = None,
) -> None:
if identity not in (self.domains + self.addresses):
if not self._is_verified_address(identity):
raise InvalidParameterValue(f"Identity '{identity}' does not exist.")
if mail_from_domain is None:
self.identity_mail_from_domains.pop(identity)
return
if not mail_from_domain.endswith(identity):
if not mail_from_domain.endswith(identity.split("@")[-1]):
raise InvalidParameterValue(
f"Provided MAIL-FROM domain '{mail_from_domain}' is not subdomain of "
f"the domain of the identity '{identity}'."
f"the domain of the identity '{identity.split('@')[-1]}'."
)
if behavior_on_mx_failure not in (None, "RejectMessage", "UseDefaultValue"):

View File

@ -1472,6 +1472,22 @@ def test_set_identity_mail_from_domain():
assert actual_attributes["BehaviorOnMXFailure"] == behaviour_on_mx_failure
assert actual_attributes["MailFromDomainStatus"] == "Success"
# Can use email address as an identity
behaviour_on_mx_failure = "RejectMessage"
mail_from_domain = "lorem.foo.com"
conn.set_identity_mail_from_domain(
Identity="test@foo.com",
MailFromDomain=mail_from_domain,
BehaviorOnMXFailure=behaviour_on_mx_failure,
)
attributes = conn.get_identity_mail_from_domain_attributes(Identities=["foo.com"])
actual_attributes = attributes["MailFromDomainAttributes"]["foo.com"]
assert actual_attributes["MailFromDomain"] == mail_from_domain
assert actual_attributes["BehaviorOnMXFailure"] == behaviour_on_mx_failure
assert actual_attributes["MailFromDomainStatus"] == "Success"
# Must unset config when MailFromDomain is null
conn.set_identity_mail_from_domain(Identity="foo.com")