与 AWS SDK或DeleteEmailTemplate一起使用 CLI - AWS SDK代码示例

AWS 文档 AWS SDK示例 GitHub 存储库中还有更多SDK示例

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

与 AWS SDK或DeleteEmailTemplate一起使用 CLI

以下代码示例演示如何使用 DeleteEmailTemplate

操作示例是大型程序的代码摘录,必须在上下文中运行。在以下代码示例中,您可以查看此操作的上下文:

.NET
AWS SDK for .NET
注意

还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库中进行设置和运行。

/// <summary> /// Deletes an email template. /// </summary> /// <param name="templateName">The name of the email template to delete.</param> /// <returns>True if successful.</returns> public async Task<bool> DeleteEmailTemplateAsync(string templateName) { var request = new DeleteEmailTemplateRequest { TemplateName = templateName }; try { var response = await _sesClient.DeleteEmailTemplateAsync(request); return response.HttpStatusCode == HttpStatusCode.OK; } catch (NotFoundException ex) { Console.WriteLine($"The email template {templateName} 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 email template: {ex.Message}"); } return false; }
  • 有关API详细信息,请参阅 “AWS SDK for .NET API参考 DeleteEmailTemplate” 中的。

Java
SDK适用于 Java 2.x
注意

还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库中进行设置和运行。

try { // Delete the template DeleteEmailTemplateRequest deleteTemplateRequest = DeleteEmailTemplateRequest.builder() .templateName(TEMPLATE_NAME) .build(); sesClient.deleteEmailTemplate(deleteTemplateRequest); System.out.println("Email template deleted: " + TEMPLATE_NAME); } catch (NotFoundException e) { // If the email template does not exist, log the error and proceed System.out.println("Email template not found. Skipping deletion..."); } catch (Exception e) { System.err.println("Error occurred while deleting the email template: " + e.getMessage()); e.printStackTrace(); }
  • 有关API详细信息,请参阅 “AWS SDK for Java 2.x API参考 DeleteEmailTemplate” 中的。

Python
SDK适用于 Python (Boto3)
注意

还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库中进行设置和运行。

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_email_template(TemplateName=TEMPLATE_NAME) print(f"Email template '{TEMPLATE_NAME}' deleted successfully.") except ClientError as e: # If the email template doesn't exist, skip and proceed if e.response["Error"]["Code"] == "NotFoundException": print(f"Email template '{TEMPLATE_NAME}' does not exist.") else: print(e)
  • 有关API详细信息,请参阅DeleteEmailTemplate中的 AWS SDKPython (Boto3) API 参考。

Rust
SDK对于 Rust
注意

还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库中进行设置和运行。

match self .client .delete_email_template() .template_name(TEMPLATE_NAME) .send() .await { Ok(_) => writeln!(self.stdout, "Email template deleted successfully.")?, Err(e) => { return Err(anyhow!("Error deleting email template: {e}")); } }