AWS SDK または CLI UpdateTemplateで を使用する - Amazon Simple Email Service

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

AWS SDK または CLI UpdateTemplateで を使用する

以下のコード例は、UpdateTemplate の使用方法を示しています。

アクション例は、より大きなプログラムからのコードの抜粋であり、コンテキスト内で実行する必要があります。次のコード例で、このアクションのコンテキストを確認できます。

C++
SDK for C++
注記

については、「」を参照してください GitHub。AWS コード例リポジトリ で全く同じ例を見つけて、設定と実行の方法を確認してください。

//! Update an Amazon Simple Email Service (Amazon SES) template. /*! \param templateName: The name of the template. \param htmlPart: The HTML body of the email. \param subjectPart: The subject line of the email. \param textPart: The plain text version of the email. \param clientConfiguration: AWS client configuration. \return bool: Function succeeded. */ bool AwsDoc::SES::updateTemplate(const Aws::String &templateName, const Aws::String &htmlPart, const Aws::String &subjectPart, const Aws::String &textPart, const Aws::Client::ClientConfiguration &clientConfiguration) { Aws::SES::SESClient sesClient(clientConfiguration); Aws::SES::Model::Template templateValues; templateValues.SetTemplateName(templateName); templateValues.SetSubjectPart(subjectPart); templateValues.SetHtmlPart(htmlPart); templateValues.SetTextPart(textPart); Aws::SES::Model::UpdateTemplateRequest updateTemplateRequest; updateTemplateRequest.SetTemplate(templateValues); Aws::SES::Model::UpdateTemplateOutcome outcome = sesClient.UpdateTemplate(updateTemplateRequest); if (outcome.IsSuccess()) { std::cout << "Successfully updated template." << std::endl; } else { std::cerr << "Error updating template. " << outcome.GetError().GetMessage() << std::endl; } return outcome.IsSuccess(); }
  • API の詳細については、「 API リファレンスUpdateTemplate」の「」を参照してください。 AWS SDK for C++

JavaScript
SDK for JavaScript (v3)
注記

については、「」を参照してください GitHub。AWS コード例リポジトリ で全く同じ例を見つけて、設定と実行の方法を確認してください。

import { UpdateTemplateCommand } 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 HTML_PART = "<h1>Hello, World!</h1>"; const createUpdateTemplateCommand = () => { return new UpdateTemplateCommand({ Template: { TemplateName: TEMPLATE_NAME, HtmlPart: HTML_PART, SubjectPart: "Example", TextPart: "Updated template text.", }, }); }; const run = async () => { const updateTemplateCommand = createUpdateTemplateCommand(); try { return await sesClient.send(updateTemplateCommand); } catch (err) { console.log("Failed to update template.", err); return err; } };
  • API の詳細については、「 API リファレンスUpdateTemplate」の「」を参照してください。 AWS SDK for JavaScript

Python
SDK for Python (Boto3)
注記

については、「」を参照してください GitHub。AWS コード例リポジトリ で全く同じ例を見つけて、設定と実行の方法を確認してください。

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 update_template(self, name, subject, text, html): """ Updates a previously created email template. :param name: The name of the template. :param subject: The subject of the email. :param text: The plain text version of the email. :param html: The HTML version of the email. """ try: template = { "TemplateName": name, "SubjectPart": subject, "TextPart": text, "HtmlPart": html, } self.ses_client.update_template(Template=template) logger.info("Updated template %s.", name) self.template = template self._extract_tags(subject, text, html) except ClientError: logger.exception("Couldn't update template %s.", name) raise
  • API の詳細については、 UpdateTemplate AWS SDK for Python (Boto3) API リファレンスの「」を参照してください。

AWS SDK デベロッパーガイドとコード例の完全なリストについては、「」を参照してくださいAWS SDK での Amazon SES の使用。このトピックには、使用開始方法に関する情報と、以前の SDK バージョンの詳細も含まれています。