SESV2 send_email with HTML body (#6927)
This commit is contained in:
parent
936656ed92
commit
a329641b3a
@ -42,11 +42,16 @@ class SESV2Response(BaseResponse):
|
|||||||
raw_data=base64.b64decode(content["Raw"]["Data"]).decode("utf-8"),
|
raw_data=base64.b64decode(content["Raw"]["Data"]).decode("utf-8"),
|
||||||
)
|
)
|
||||||
elif "Simple" in content:
|
elif "Simple" in content:
|
||||||
|
content_body = content["Simple"]["Body"]
|
||||||
|
if "Html" in content_body:
|
||||||
|
body = content_body["Html"]["Data"]
|
||||||
|
else:
|
||||||
|
body = content_body["Text"]["Data"]
|
||||||
message = self.sesv2_backend.send_email( # type: ignore
|
message = self.sesv2_backend.send_email( # type: ignore
|
||||||
source=from_email_address,
|
source=from_email_address,
|
||||||
destinations=destination,
|
destinations=destination,
|
||||||
subject=content["Simple"]["Subject"]["Data"],
|
subject=content["Simple"]["Subject"]["Data"],
|
||||||
body=content["Simple"]["Body"]["Text"]["Data"],
|
body=body,
|
||||||
)
|
)
|
||||||
elif "Template" in content:
|
elif "Template" in content:
|
||||||
raise NotImplementedError("Template functionality not ready")
|
raise NotImplementedError("Template functionality not ready")
|
||||||
|
@ -2,7 +2,7 @@ import boto3
|
|||||||
from botocore.exceptions import ClientError
|
from botocore.exceptions import ClientError
|
||||||
import pytest
|
import pytest
|
||||||
from moto import mock_sesv2, mock_ses, settings
|
from moto import mock_sesv2, mock_ses, settings
|
||||||
from moto.ses.models import ses_backends, RawMessage
|
from moto.ses.models import ses_backends, RawMessage, Message
|
||||||
from tests import DEFAULT_ACCOUNT_ID
|
from tests import DEFAULT_ACCOUNT_ID
|
||||||
from ..test_ses.test_ses_boto3 import get_raw_email
|
from ..test_ses.test_ses_boto3 import get_raw_email
|
||||||
|
|
||||||
@ -48,11 +48,44 @@ def test_send_email(ses_v1): # pylint: disable=redefined-outer-name
|
|||||||
|
|
||||||
if not settings.TEST_SERVER_MODE:
|
if not settings.TEST_SERVER_MODE:
|
||||||
backend = ses_backends[DEFAULT_ACCOUNT_ID]["us-east-1"]
|
backend = ses_backends[DEFAULT_ACCOUNT_ID]["us-east-1"]
|
||||||
msg: RawMessage = backend.sent_messages[0]
|
msg: Message = backend.sent_messages[0]
|
||||||
assert msg.subject == "test subject"
|
assert msg.subject == "test subject"
|
||||||
assert msg.body == "test body"
|
assert msg.body == "test body"
|
||||||
|
|
||||||
|
|
||||||
|
@mock_sesv2
|
||||||
|
def test_send_html_email(ses_v1): # pylint: disable=redefined-outer-name
|
||||||
|
# Setup
|
||||||
|
conn = boto3.client("sesv2", region_name="us-east-1")
|
||||||
|
ses_v1.verify_domain_identity(Domain="example.com")
|
||||||
|
kwargs = dict(
|
||||||
|
FromEmailAddress="test@example.com",
|
||||||
|
Destination={
|
||||||
|
"ToAddresses": ["test_to@example.com"],
|
||||||
|
},
|
||||||
|
Content={
|
||||||
|
"Simple": {
|
||||||
|
"Subject": {"Data": "test subject"},
|
||||||
|
"Body": {"Html": {"Data": "<h1>Test HTML</h1>"}},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
# Execute
|
||||||
|
conn.send_email(**kwargs)
|
||||||
|
|
||||||
|
# Verify
|
||||||
|
send_quota = ses_v1.get_send_quota()
|
||||||
|
sent_count = int(send_quota["SentLast24Hours"])
|
||||||
|
assert sent_count == 1
|
||||||
|
|
||||||
|
if not settings.TEST_SERVER_MODE:
|
||||||
|
backend = ses_backends[DEFAULT_ACCOUNT_ID]["us-east-1"]
|
||||||
|
msg: Message = backend.sent_messages[0]
|
||||||
|
assert msg.subject == "test subject"
|
||||||
|
assert msg.body == "<h1>Test HTML</h1>"
|
||||||
|
|
||||||
|
|
||||||
@mock_sesv2
|
@mock_sesv2
|
||||||
def test_send_raw_email(ses_v1): # pylint: disable=redefined-outer-name
|
def test_send_raw_email(ses_v1): # pylint: disable=redefined-outer-name
|
||||||
# Setup
|
# Setup
|
||||||
|
Loading…
Reference in New Issue
Block a user