Gunakan DeleteTemplate dengan AWS SDKatau CLI - Layanan Email Sederhana Amazon

Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.

Gunakan DeleteTemplate dengan AWS SDKatau CLI

Contoh kode berikut menunjukkan cara menggunakanDeleteTemplate.

Contoh tindakan adalah kutipan kode dari program yang lebih besar dan harus dijalankan dalam konteks. Anda dapat melihat tindakan ini dalam konteks dalam contoh kode berikut:

.NET
AWS SDK for .NET
catatan

Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara mengatur dan menjalankan di AWS Repositori Contoh Kode.

/// <summary> /// Delete an email template. /// </summary> /// <param name="templateName">Name of the template.</param> /// <returns>True if successful.</returns> public async Task<bool> DeleteEmailTemplateAsync(string templateName) { var success = false; try { var response = await _amazonSimpleEmailService.DeleteTemplateAsync( new DeleteTemplateRequest { TemplateName = templateName }); success = response.HttpStatusCode == HttpStatusCode.OK; } catch (Exception ex) { Console.WriteLine("DeleteEmailTemplateAsync failed with exception: " + ex.Message); } return success; }
  • Untuk API detailnya, lihat DeleteTemplatedi AWS SDK for .NET APIReferensi.

C++
SDKuntuk C ++
catatan

Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara mengatur dan menjalankan di AWS Repositori Contoh Kode.

//! Delete an Amazon Simple Email Service (Amazon SES) template. /*! \param templateName: The name for the template. \param clientConfiguration: AWS client configuration. \return bool: Function succeeded. */ bool AwsDoc::SES::deleteTemplate(const Aws::String &templateName, const Aws::Client::ClientConfiguration &clientConfiguration) { Aws::SES::SESClient sesClient(clientConfiguration); Aws::SES::Model::DeleteTemplateRequest deleteTemplateRequest; deleteTemplateRequest.SetTemplateName(templateName); Aws::SES::Model::DeleteTemplateOutcome outcome = sesClient.DeleteTemplate( deleteTemplateRequest); if (outcome.IsSuccess()) { std::cout << "Successfully deleted template." << std::endl; } else { std::cerr << "Error deleting template. " << outcome.GetError().GetMessage() << std::endl; } return outcome.IsSuccess(); }
  • Untuk API detailnya, lihat DeleteTemplatedi AWS SDK for C++ APIReferensi.

JavaScript
SDKuntuk JavaScript (v3)
catatan

Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara mengatur dan menjalankan di AWS Repositori Contoh Kode.

import { DeleteTemplateCommand } from "@aws-sdk/client-ses"; import { getUniqueName } from "@aws-doc-sdk-examples/lib/utils/util-string.js"; import { sesClient } from "./libs/sesClient.js"; const TEMPLATE_NAME = getUniqueName("TemplateName"); const createDeleteTemplateCommand = (templateName) => new DeleteTemplateCommand({ TemplateName: templateName }); const run = async () => { const deleteTemplateCommand = createDeleteTemplateCommand(TEMPLATE_NAME); try { return await sesClient.send(deleteTemplateCommand); } catch (err) { console.log("Failed to delete template.", err); return err; } };
  • Untuk API detailnya, lihat DeleteTemplatedi AWS SDK for JavaScript APIReferensi.

Python
SDKuntuk Python (Boto3)
catatan

Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara mengatur dan menjalankan di AWS Repositori Contoh Kode.

class SesTemplate: """Encapsulates Amazon SES template functions.""" def __init__(self, ses_client): """ :param ses_client: A Boto3 Amazon SES client. """ self.ses_client = ses_client self.template = None self.template_tags = set() def _extract_tags(self, subject, text, html): """ Extracts tags from a template as a set of unique values. :param subject: The subject of the email. :param text: The text version of the email. :param html: The html version of the email. """ self.template_tags = set(re.findall(TEMPLATE_REGEX, subject + text + html)) logger.info("Extracted template tags: %s", self.template_tags) def delete_template(self): """ Deletes an email template. """ try: self.ses_client.delete_template(TemplateName=self.template["TemplateName"]) logger.info("Deleted template %s.", self.template["TemplateName"]) self.template = None self.template_tags = None except ClientError: logger.exception( "Couldn't delete template %s.", self.template["TemplateName"] ) raise
  • Untuk API detailnya, lihat DeleteTemplatedi AWS SDKuntuk Python (Boto3) Referensi. API

Untuk daftar lengkap AWS SDKpanduan pengembang dan contoh kode, lihatMenggunakan Amazon SES dengan AWS SDK. Topik ini juga mencakup informasi tentang memulai dan detail tentang SDK versi sebelumnya.