MCPcopy Create free account
hub / github.com/awsdocs/aws-doc-sdk-examples / send_email

Method send_email

python/example_code/ses/ses_email.py:66–104  ·  view source on GitHub ↗

Sends an email. Note: If your account is in the Amazon SES sandbox, the source and destination email accounts must both be verified. :param source: The source email account. :param destination: The destination email account. :param subject: The sub

(self, source, destination, subject, text, html, reply_tos=None)

Source from the content-addressed store, hash-verified

64
65 # snippet-start:[python.example_code.ses.SendEmail]
66 def send_email(self, source, destination, subject, text, html, reply_tos=None):
67 """
68 Sends an email.
69
70 Note: If your account is in the Amazon SES sandbox, the source and
71 destination email accounts must both be verified.
72
73 :param source: The source email account.
74 :param destination: The destination email account.
75 :param subject: The subject of the email.
76 :param text: The plain text version of the body of the email.
77 :param html: The HTML version of the body of the email.
78 :param reply_tos: Email accounts that will receive a reply if the recipient
79 replies to the message.
80 :return: The ID of the message, assigned by Amazon SES.
81 """
82 send_args = {
83 "Source": source,
84 "Destination": destination.to_service_format(),
85 "Message": {
86 "Subject": {"Data": subject},
87 "Body": {"Text": {"Data": text}, "Html": {"Data": html}},
88 },
89 }
90 if reply_tos is not None:
91 send_args["ReplyToAddresses"] = reply_tos
92 try:
93 response = self.ses_client.send_email(**send_args)
94 message_id = response["MessageId"]
95 logger.info(
96 "Sent mail %s from %s to %s.", message_id, source, destination.tos
97 )
98 except ClientError:
99 logger.exception(
100 "Couldn't send mail from %s to %s.", source, destination.tos
101 )
102 raise
103 else:
104 return message_id
105
106 # snippet-end:[python.example_code.ses.SendEmail]
107

Callers 5

usage_demoFunction · 0.95
test_send_emailFunction · 0.95
postMethod · 0.45
postMethod · 0.45
postMethod · 0.45

Calls 1

to_service_formatMethod · 0.80

Tested by 1

test_send_emailFunction · 0.76