///<summary>/// Creates a contact list with the specified name.///</summary>///<param name="contactListName">The name of the contact list.</param>///<returns>True if successful.</returns>publicasync Task<bool> CreateContactListAsync(string contactListName){var request = new CreateContactListRequest
{
ContactListName = contactListName
};
try{var response = await _sesClient.CreateContactListAsync(request);
return response.HttpStatusCode == HttpStatusCode.OK;
}
catch (AlreadyExistsException ex)
{
Console.WriteLine($"Contact list with name {contactListName} already exists.");
Console.WriteLine(ex.Message);
returntrue;
}
catch (LimitExceededException ex)
{
Console.WriteLine("The limit for contact lists has been exceeded.");
Console.WriteLine(ex.Message);
}
catch (TooManyRequestsException ex)
{
Console.WriteLine("Too many requests were made. Please try again later.");
Console.WriteLine(ex.Message);
}
catch (Exception ex)
{
Console.WriteLine($"An error occurred while creating the contact list: {ex.Message}");
}
returnfalse;
}
defmain():"""
The main function that orchestrates the execution of the workflow.
"""print(INTRO)
ses_client = boto3.client("sesv2")
workflow = SESv2Workflow(ses_client)
try:
workflow.prepare_application()
workflow.gather_subscriber_email_addresses()
workflow.send_coupon_newsletter()
workflow.monitor_and_review()
except ClientError as e:
print_error(e)
workflow.clean_up()
classSESv2Workflow:"""
A class to manage the SES v2 Coupon Newsletter Workflow.
"""def__init__(self, ses_client, sleep=True):
self.ses_client = ses_client
self.sleep = sleep
try:
self.ses_client.create_contact_list(ContactListName=CONTACT_LIST_NAME)
print(f"Contact list '{CONTACT_LIST_NAME}' created successfully.")
except ClientError as e:
# If the contact list already exists, skip and proceedif e.response["Error"]["Code"] == "AlreadyExistsException":
print(f"Contact list '{CONTACT_LIST_NAME}' already exists.")
else:
raise e
如需 API 詳細資訊,請參閱《適用於 AWS Python (Boto3) 的 SDK API 參考》中的 CreateContactList。
///<summary>/// Creates a contact list with the specified name.///</summary>///<param name="contactListName">The name of the contact list.</param>///<returns>True if successful.</returns>publicasync Task<bool> CreateContactListAsync(string contactListName){var request = new CreateContactListRequest
{
ContactListName = contactListName
};
try{var response = await _sesClient.CreateContactListAsync(request);
return response.HttpStatusCode == HttpStatusCode.OK;
}
catch (AlreadyExistsException ex)
{
Console.WriteLine($"Contact list with name {contactListName} already exists.");
Console.WriteLine(ex.Message);
returntrue;
}
catch (LimitExceededException ex)
{
Console.WriteLine("The limit for contact lists has been exceeded.");
Console.WriteLine(ex.Message);
}
catch (TooManyRequestsException ex)
{
Console.WriteLine("Too many requests were made. Please try again later.");
Console.WriteLine(ex.Message);
}
catch (Exception ex)
{
Console.WriteLine($"An error occurred while creating the contact list: {ex.Message}");
}
returnfalse;
}