SES: set_identity_mail_from_domain() - the Identity can be an email (#6755)
This commit is contained in:
parent
c59fee5d35
commit
5af4421524
@ -165,7 +165,7 @@ class SESBackend(BaseBackend):
|
|||||||
return True
|
return True
|
||||||
if address in self.email_addresses:
|
if address in self.email_addresses:
|
||||||
return True
|
return True
|
||||||
_, host = address.split("@", 1)
|
host = address.split("@", 1)[-1]
|
||||||
return host in self.domains
|
return host in self.domains
|
||||||
|
|
||||||
def verify_email_identity(self, address: str) -> None:
|
def verify_email_identity(self, address: str) -> None:
|
||||||
@ -572,17 +572,17 @@ class SESBackend(BaseBackend):
|
|||||||
mail_from_domain: Optional[str] = None,
|
mail_from_domain: Optional[str] = None,
|
||||||
behavior_on_mx_failure: Optional[str] = None,
|
behavior_on_mx_failure: Optional[str] = None,
|
||||||
) -> 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.")
|
raise InvalidParameterValue(f"Identity '{identity}' does not exist.")
|
||||||
|
|
||||||
if mail_from_domain is None:
|
if mail_from_domain is None:
|
||||||
self.identity_mail_from_domains.pop(identity)
|
self.identity_mail_from_domains.pop(identity)
|
||||||
return
|
return
|
||||||
|
|
||||||
if not mail_from_domain.endswith(identity):
|
if not mail_from_domain.endswith(identity.split("@")[-1]):
|
||||||
raise InvalidParameterValue(
|
raise InvalidParameterValue(
|
||||||
f"Provided MAIL-FROM domain '{mail_from_domain}' is not subdomain of "
|
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"):
|
if behavior_on_mx_failure not in (None, "RejectMessage", "UseDefaultValue"):
|
||||||
|
@ -1472,6 +1472,22 @@ def test_set_identity_mail_from_domain():
|
|||||||
assert actual_attributes["BehaviorOnMXFailure"] == behaviour_on_mx_failure
|
assert actual_attributes["BehaviorOnMXFailure"] == behaviour_on_mx_failure
|
||||||
assert actual_attributes["MailFromDomainStatus"] == "Success"
|
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
|
# Must unset config when MailFromDomain is null
|
||||||
conn.set_identity_mail_from_domain(Identity="foo.com")
|
conn.set_identity_mail_from_domain(Identity="foo.com")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user