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

Function usage_demo

python/example_code/ses/ses_email.py:158–251  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

156
157# snippet-start:[python.example_code.ses.Scenario_SendEmail]
158def usage_demo():
159 print("-" * 88)
160 print("Welcome to the Amazon Simple Email Service (Amazon SES) email demo!")
161 print("-" * 88)
162
163 logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(message)s")
164
165 ses_client = boto3.client("ses")
166 ses_identity = SesIdentity(ses_client)
167 ses_mail_sender = SesMailSender(ses_client)
168 ses_template = SesTemplate(ses_client)
169 email = input("Enter an email address to send mail with Amazon SES: ")
170 status = ses_identity.get_identity_status(email)
171 verified = status == "Success"
172 if not verified:
173 answer = input(
174 f"The address '{email}' is not verified with Amazon SES. Unless your "
175 f"Amazon SES account is out of sandbox, you can send mail only from "
176 f"and to verified accounts. Do you want to verify this account for use "
177 f"with Amazon SES? If yes, the address will receive a verification "
178 f"email (y/n): "
179 )
180 if answer.lower() == "y":
181 ses_identity.verify_email_identity(email)
182 print(f"Follow the steps in the email to {email} to complete verification.")
183 print("Waiting for verification...")
184 try:
185 ses_identity.wait_until_identity_exists(email)
186 print(f"Identity verified for {email}.")
187 verified = True
188 except WaiterError:
189 print(
190 f"Verification timeout exceeded. You must complete the "
191 f"steps in the email sent to {email} to verify the address."
192 )
193
194 if verified:
195 test_message_text = "Hello from the Amazon SES mail demo!"
196 test_message_html = "<p>Hello!</p><p>From the <b>Amazon SES</b> mail demo!</p>"
197
198 print(f"Sending mail from {email} to {email}.")
199 ses_mail_sender.send_email(
200 email,
201 SesDestination([email]),
202 "Amazon SES demo",
203 test_message_text,
204 test_message_html,
205 )
206 input("Mail sent. Check your inbox and press Enter to continue.")
207
208 template = {
209 "name": "doc-example-template",
210 "subject": "Example of an email template.",
211 "text": "This is what {{name}} will {{action}} if {{name}} can't display "
212 "HTML.",
213 "html": "<p><i>This</i> is what {{name}} will {{action}} if {{name}} "
214 "<b>can</b> display HTML.</p>",
215 }

Callers 1

ses_email.pyFile · 0.70

Calls 15

get_identity_statusMethod · 0.95
verify_email_identityMethod · 0.95
send_emailMethod · 0.95
create_templateMethod · 0.95
verify_tagsMethod · 0.95
send_templated_emailMethod · 0.95
nameMethod · 0.95
delete_templateMethod · 0.95
delete_identityMethod · 0.95
SesIdentityClass · 0.90
SesTemplateClass · 0.90

Tested by

no test coverage detected