Les traductions sont fournies par des outils de traduction automatique. En cas de conflit entre le contenu d'une traduction et celui de la version originale en anglais, la version anglaise prévaudra.
Les exemples de code suivants montrent comment utiliserDeleteContactList
.
Les exemples d’actions sont des extraits de code de programmes de plus grande envergure et doivent être exécutés en contexte. Vous pouvez voir cette action en contexte dans l’exemple de code suivant :
- .NET
-
- AWS SDK for .NET
-
/// <summary>
/// Deletes a contact list and all contacts within it.
/// </summary>
/// <param name="contactListName">The name of the contact list to delete.</param>
/// <returns>True if successful.</returns>
public async Task<bool> DeleteContactListAsync(string contactListName)
{
var request = new DeleteContactListRequest
{
ContactListName = contactListName
};
try
{
var response = await _sesClient.DeleteContactListAsync(request);
return response.HttpStatusCode == HttpStatusCode.OK;
}
catch (ConcurrentModificationException ex)
{
Console.WriteLine($"The contact list {contactListName} is being modified by another operation or thread.");
Console.WriteLine(ex.Message);
}
catch (NotFoundException ex)
{
Console.WriteLine($"The contact list {contactListName} does not exist.");
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 deleting the contact list: {ex.Message}");
}
return false;
}
- Java
-
- SDKpour Java 2.x
-
try {
// Delete the contact list
DeleteContactListRequest deleteContactListRequest = DeleteContactListRequest.builder()
.contactListName(CONTACT_LIST_NAME)
.build();
sesClient.deleteContactList(deleteContactListRequest);
System.out.println("Contact list deleted: " + CONTACT_LIST_NAME);
} catch (NotFoundException e) {
// If the contact list does not exist, log the error and proceed
System.out.println("Contact list not found. Skipping deletion...");
} catch (Exception e) {
System.err.println("Error occurred while deleting the contact list: " + e.getMessage());
e.printStackTrace();
}
- Python
-
- SDKpour Python (Boto3)
-
def main():
"""
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()
class SESv2Workflow:
"""
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.delete_contact_list(ContactListName=CONTACT_LIST_NAME)
print(f"Contact list '{CONTACT_LIST_NAME}' deleted successfully.")
except ClientError as e:
# If the contact list doesn't exist, skip and proceed
if e.response["Error"]["Code"] == "NotFoundException":
print(f"Contact list '{CONTACT_LIST_NAME}' does not exist.")
else:
print(e)
- Rust
-
- SDKpour Rust
-
match self
.client
.delete_contact_list()
.contact_list_name(CONTACT_LIST_NAME)
.send()
.await
{
Ok(_) => writeln!(self.stdout, "Contact list deleted successfully.")?,
Err(e) => return Err(anyhow!("Error deleting contact list: {e}")),
}
Pour obtenir la liste complète des guides AWS SDK de développement et des exemples de code, consultezUtilisation d'Amazon SES avec un AWS SDK. Cette rubrique inclut également des informations sur la mise en route et des détails sur SDK les versions précédentes.