Verwenden Sie es CreateTemplate mit einem oder AWS SDK CLI - AWS SDK-Codebeispiele

Weitere AWS SDK Beispiele sind im Repo AWS Doc SDK Examples GitHub verfügbar.

Die vorliegende Übersetzung wurde maschinell erstellt. Im Falle eines Konflikts oder eines Widerspruchs zwischen dieser übersetzten Fassung und der englischen Fassung (einschließlich infolge von Verzögerungen bei der Übersetzung) ist die englische Fassung maßgeblich.

Verwenden Sie es CreateTemplate mit einem oder AWS SDK CLI

Die folgenden Codebeispiele zeigen, wie man es benutztCreateTemplate.

Beispiele für Aktionen sind Codeauszüge aus größeren Programmen und müssen im Kontext ausgeführt werden. Im folgenden Codebeispiel können Sie diese Aktion im Kontext sehen:

.NET
AWS SDK for .NET
Anmerkung

Es gibt noch mehr dazu GitHub. Sie sehen das vollständige Beispiel und erfahren, wie Sie das AWS -Code-Beispiel-Repository einrichten und ausführen.

/// <summary> /// Create an email template. /// </summary> /// <param name="name">Name of the template.</param> /// <param name="subject">Email subject.</param> /// <param name="text">Email body text.</param> /// <param name="html">Email HTML body text.</param> /// <returns>True if successful.</returns> public async Task<bool> CreateEmailTemplateAsync(string name, string subject, string text, string html) { var success = false; try { var response = await _amazonSimpleEmailService.CreateTemplateAsync( new CreateTemplateRequest { Template = new Template { TemplateName = name, SubjectPart = subject, TextPart = text, HtmlPart = html } }); success = response.HttpStatusCode == HttpStatusCode.OK; } catch (Exception ex) { Console.WriteLine("CreateEmailTemplateAsync failed with exception: " + ex.Message); } return success; }
  • APIEinzelheiten finden Sie CreateTemplateunter AWS SDK for .NET APIReferenz.

C++
SDKfür C++
Anmerkung

Es gibt noch mehr dazu GitHub. Sie sehen das vollständige Beispiel und erfahren, wie Sie das AWS -Code-Beispiel-Repository einrichten und ausführen.

//! Create 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::createTemplate(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::CreateTemplateRequest createTemplateRequest; Aws::SES::Model::Template aTemplate; aTemplate.SetTemplateName(templateName); aTemplate.SetHtmlPart(htmlPart); aTemplate.SetSubjectPart(subjectPart); aTemplate.SetTextPart(textPart); createTemplateRequest.SetTemplate(aTemplate); Aws::SES::Model::CreateTemplateOutcome outcome = sesClient.CreateTemplate( createTemplateRequest); if (outcome.IsSuccess()) { std::cout << "Successfully created template." << templateName << "." << std::endl; } else { std::cerr << "Error creating template. " << outcome.GetError().GetMessage() << std::endl; } return outcome.IsSuccess(); }
  • APIEinzelheiten finden Sie CreateTemplateunter AWS SDK for C++ APIReferenz.

JavaScript
SDKfür JavaScript (v3)
Anmerkung

Es gibt noch mehr dazu GitHub. Sie sehen das vollständige Beispiel und erfahren, wie Sie das AWS -Code-Beispiel-Repository einrichten und ausführen.

import { CreateTemplateCommand } from "@aws-sdk/client-ses"; import { sesClient } from "./libs/sesClient.js"; import { getUniqueName } from "@aws-doc-sdk-examples/lib/utils/util-string.js"; const TEMPLATE_NAME = getUniqueName("TestTemplateName"); const createCreateTemplateCommand = () => { return new CreateTemplateCommand({ /** * The template feature in Amazon SES is based on the Handlebars template system. */ Template: { /** * The name of an existing template in Amazon SES. */ TemplateName: TEMPLATE_NAME, HtmlPart: ` <h1>Hello, {{contact.firstName}}!</h1> <p> Did you know Amazon has a mascot named Peccy? </p> `, SubjectPart: "Amazon Tip", }, }); }; const run = async () => { const createTemplateCommand = createCreateTemplateCommand(); try { return await sesClient.send(createTemplateCommand); } catch (err) { console.log("Failed to create template.", err); return err; } };
  • APIEinzelheiten finden Sie CreateTemplateunter AWS SDK for JavaScript APIReferenz.

Python
SDKfür Python (Boto3)
Anmerkung

Es gibt noch mehr dazu. GitHub Sie sehen das vollständige Beispiel und erfahren, wie Sie das AWS -Code-Beispiel-Repository einrichten und ausführen.

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 create_template(self, name, subject, text, html): """ Creates an 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.create_template(Template=template) logger.info("Created template %s.", name) self.template = template self._extract_tags(subject, text, html) except ClientError: logger.exception("Couldn't create template %s.", name) raise
  • APIEinzelheiten finden Sie unter CreateTemplatePython (Boto3) API -Referenz.AWS SDK