Há mais exemplos de AWS SDK disponíveis no repositório AWS Doc SDK Examples
As traduções são geradas por tradução automática. Em caso de conflito entre o conteúdo da tradução e da versão original em inglês, a versão em inglês prevalecerá.
Use UpdateTemplate com um AWS SDK
Os exemplos de código a seguir mostram como usar o UpdateTemplate.
Exemplos de ações são trechos de código de programas maiores e devem ser executados em contexto. É possível ver essa ação em contexto no seguinte exemplo de código:
- C++
-
- SDK para C++
-
nota
Tem mais sobre GitHub. Encontre o exemplo completo e saiba como configurar e executar no AWS Code Examples Repository
. //! 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(); }-
Para obter detalhes da API, consulte UpdateTemplatea Referência AWS SDK para C++ da API.
-
- JavaScript
-
- SDK para JavaScript (v3)
-
nota
Tem mais sobre GitHub. Encontre o exemplo completo e saiba como configurar e executar no AWS Code Examples Repository
. 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; } };-
Para obter detalhes da API, consulte UpdateTemplatea Referência AWS SDK para JavaScript da API.
-
- Python
-
- SDK para Python (Boto3)
-
nota
Tem mais sobre GitHub. Encontre o exemplo completo e saiba como configurar e executar no AWS Code Examples Repository
. 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-
Para obter detalhes da API, consulte a UpdateTemplateReferência da API AWS SDK for Python (Boto3).
-
- SAP ABAP
-
- SDK para SAP ABAP
-
nota
Tem mais sobre GitHub. Encontre o exemplo completo e saiba como configurar e executar no AWS Code Examples Repository
. DATA(lo_template) = NEW /aws1/cl_sestemplate( iv_templatename = iv_name iv_subjectpart = iv_subject iv_textpart = iv_text iv_htmlpart = iv_html ). TRY. lo_ses->updatetemplate( io_template = lo_template ). MESSAGE 'Template updated successfully' TYPE 'I'. CATCH /aws1/cx_sestmpldoesnotexistex INTO DATA(lo_ex1). DATA(lv_error) = |Template does not exist: { lo_ex1->get_text( ) }|. MESSAGE lv_error TYPE 'I'. RAISE EXCEPTION lo_ex1. CATCH /aws1/cx_sesinvalidtemplateex INTO DATA(lo_ex2). lv_error = |Invalid template: { lo_ex2->get_text( ) }|. MESSAGE lv_error TYPE 'I'. RAISE EXCEPTION lo_ex2. CATCH /aws1/cx_rt_generic INTO DATA(lo_ex_generic). lv_error = |An error occurred: { lo_ex_generic->get_text( ) }|. MESSAGE lv_error TYPE 'I'. RAISE EXCEPTION lo_ex_generic. ENDTRY.-
Para obter detalhes da API, consulte a UpdateTemplatereferência da API AWS SDK for SAP ABAP.
-