Email template system for creating reusable email formats with variable substitution and bulk email operations. This module provides comprehensive template lifecycle management including creation, updates, testing, and bulk sending capabilities.
Create, update, delete, and retrieve email templates.
/**
* Creates a new email template
* @param input - Template definition
* @returns Promise with operation result
*/
interface CreateTemplateCommandInput {
/** Template definition including name and content */
Template: Template;
}
interface CreateTemplateCommandOutput {
$metadata: ResponseMetadata;
}
/**
* Updates an existing email template
* @param input - Updated template definition
* @returns Promise with operation result
*/
interface UpdateTemplateCommandInput {
/** Updated template definition */
Template: Template;
}
interface UpdateTemplateCommandOutput {
$metadata: ResponseMetadata;
}
/**
* Deletes an email template
* @param input - Template name to delete
* @returns Promise with operation result
*/
interface DeleteTemplateCommandInput {
/** Name of template to delete */
TemplateName: string;
}
interface DeleteTemplateCommandOutput {
$metadata: ResponseMetadata;
}
/**
* Retrieves an email template
* @param input - Template name to retrieve
* @returns Promise with template definition
*/
interface GetTemplateCommandInput {
/** Name of template to retrieve */
TemplateName: string;
}
interface GetTemplateCommandOutput {
/** Template definition */
Template?: Template;
$metadata: ResponseMetadata;
}Usage Example:
import {
SESClient,
CreateTemplateCommand,
GetTemplateCommand,
UpdateTemplateCommand
} from "@aws-sdk/client-ses";
const client = new SESClient({ region: "us-east-1" });
// Create a template
const createCommand = new CreateTemplateCommand({
Template: {
TemplateName: "WelcomeEmail",
Subject: "Welcome to {{company_name}}, {{first_name}}!",
TextPart: `Hello {{first_name}},
Welcome to {{company_name}}! We're excited to have you on board.
Your account details:
- Email: {{email}}
- Plan: {{plan_name}}
Best regards,
The {{company_name}} Team`,
HtmlPart: `<h1>Welcome to {{company_name}}, {{first_name}}!</h1>
<p>We're excited to have you on board.</p>
<h2>Your account details:</h2>
<ul>
<li><strong>Email:</strong> {{email}}</li>
<li><strong>Plan:</strong> {{plan_name}}</li>
</ul>
<p>Best regards,<br>The {{company_name}} Team</p>`,
},
});
await client.send(createCommand);
console.log("Template created successfully");
// Retrieve the template
const getCommand = new GetTemplateCommand({
TemplateName: "WelcomeEmail",
});
const template = await client.send(getCommand);
console.log("Retrieved template:", template.Template);List all available email templates.
/**
* Lists all email templates
* @param input - Optional pagination parameters
* @returns Promise with list of templates
*/
interface ListTemplatesCommandInput {
/** Token for pagination */
NextToken?: string;
/** Maximum number of results */
MaxItems?: number;
}
interface ListTemplatesCommandOutput {
/** List of template metadata */
TemplatesMetadata?: TemplateMetadata[];
/** Token for next page of results */
NextToken?: string;
$metadata: ResponseMetadata;
}
interface TemplateMetadata {
/** Template name */
Name?: string;
/** Template creation timestamp */
CreatedTimestamp?: Date;
}Test template rendering with sample data.
/**
* Tests template rendering with provided data
* @param input - Template name and test data
* @returns Promise with rendered template
*/
interface TestRenderTemplateCommandInput {
/** Name of template to test */
TemplateName: string;
/** JSON string containing template data */
TemplateData: string;
}
interface TestRenderTemplateCommandOutput {
/** Rendered subject line */
Subject?: string;
/** Rendered text part */
TextPart?: string;
/** Rendered HTML part */
HtmlPart?: string;
$metadata: ResponseMetadata;
}Usage Example:
import { SESClient, TestRenderTemplateCommand } from "@aws-sdk/client-ses";
const client = new SESClient({ region: "us-east-1" });
const testCommand = new TestRenderTemplateCommand({
TemplateName: "WelcomeEmail",
TemplateData: JSON.stringify({
first_name: "John",
company_name: "Acme Corp",
email: "john@example.com",
plan_name: "Premium",
}),
});
const rendered = await client.send(testCommand);
console.log("Rendered subject:", rendered.Subject);
console.log("Rendered text:", rendered.TextPart);
console.log("Rendered HTML:", rendered.HtmlPart);Send emails using templates with personalized data.
/**
* Sends an email using a template
* @param input - Template name, recipient, and personalization data
* @returns Promise with message ID
*/
interface SendTemplatedEmailCommandInput {
/** Source email address */
Source: string;
/** Email destination */
Destination: Destination;
/** Reply-to addresses */
ReplyToAddresses?: string[];
/** Return path for bounces */
ReturnPath?: string;
/** Template name to use */
Template: string;
/** JSON string with template data */
TemplateData: string;
/** Template ARN for cross-account access */
TemplateArn?: string;
/** Configuration set for tracking */
ConfigurationSetName?: string;
/** Message tags */
Tags?: MessageTag[];
/** Source ARN for cross-account sending */
SourceArn?: string;
/** Return path ARN */
ReturnPathArn?: string;
}
interface SendTemplatedEmailCommandOutput {
/** Unique message identifier */
MessageId: string;
$metadata: ResponseMetadata;
}Usage Example:
import { SESClient, SendTemplatedEmailCommand } from "@aws-sdk/client-ses";
const client = new SESClient({ region: "us-east-1" });
const sendCommand = new SendTemplatedEmailCommand({
Source: "noreply@acmecorp.com",
Destination: {
ToAddresses: ["john@example.com"],
},
Template: "WelcomeEmail",
TemplateData: JSON.stringify({
first_name: "John",
company_name: "Acme Corp",
email: "john@example.com",
plan_name: "Premium",
}),
ConfigurationSetName: "user-onboarding",
Tags: [
{ Name: "campaign", Value: "welcome" },
{ Name: "user_type", Value: "premium" },
],
});
const response = await client.send(sendCommand);
console.log("Templated email sent:", response.MessageId);Send the same template to multiple recipients with personalized data.
/**
* Sends bulk templated emails to multiple recipients
* @param input - Template, source, and recipient data
* @returns Promise with per-recipient status
*/
interface SendBulkTemplatedEmailCommandInput {
/** Source email address */
Source: string;
/** Template name to use */
Template: string;
/** Default template data (JSON string) */
DefaultTemplateData?: string;
/** List of destinations with personalized data */
Destinations: BulkEmailDestination[];
/** Reply-to addresses */
ReplyToAddresses?: string[];
/** Return path for bounces */
ReturnPath?: string;
/** Configuration set for tracking */
ConfigurationSetName?: string;
/** Default message tags */
DefaultTags?: MessageTag[];
/** Template ARN for cross-account access */
TemplateArn?: string;
/** Source ARN for cross-account sending */
SourceArn?: string;
/** Return path ARN */
ReturnPathArn?: string;
}
interface BulkEmailDestination {
/** Recipient information */
Destination: Destination;
/** Recipient-specific template data (JSON string) */
ReplacementTemplateData?: string;
/** Recipient-specific message tags */
ReplacementTags?: MessageTag[];
}
interface SendBulkTemplatedEmailCommandOutput {
/** Per-recipient sending status */
Status: BulkEmailDestinationStatus[];
$metadata: ResponseMetadata;
}
interface BulkEmailDestinationStatus {
/** Sending status */
Status?: BulkEmailStatus;
/** Error message if failed */
Error?: string;
/** Message ID if successful */
MessageId?: string;
}Usage Example:
import {
SESClient,
SendBulkTemplatedEmailCommand
} from "@aws-sdk/client-ses";
const client = new SESClient({ region: "us-east-1" });
const bulkCommand = new SendBulkTemplatedEmailCommand({
Source: "noreply@acmecorp.com",
Template: "WelcomeEmail",
DefaultTemplateData: JSON.stringify({
company_name: "Acme Corp",
}),
Destinations: [
{
Destination: { ToAddresses: ["john@example.com"] },
ReplacementTemplateData: JSON.stringify({
first_name: "John",
email: "john@example.com",
plan_name: "Premium",
}),
},
{
Destination: { ToAddresses: ["jane@example.com"] },
ReplacementTemplateData: JSON.stringify({
first_name: "Jane",
email: "jane@example.com",
plan_name: "Basic",
}),
},
],
ConfigurationSetName: "bulk-welcome",
});
const response = await client.send(bulkCommand);
response.Status.forEach((status, index) => {
if (status.Status === "Success") {
console.log(`Email ${index + 1} sent: ${status.MessageId}`);
} else {
console.error(`Email ${index + 1} failed: ${status.Error}`);
}
});Create and manage custom verification email templates.
/**
* Creates a custom verification email template
* @param input - Template definition
* @returns Promise with operation result
*/
interface CreateCustomVerificationEmailTemplateCommandInput {
/** Template name */
TemplateName: string;
/** Email sender address */
FromEmailAddress: string;
/** Email subject */
TemplateSubject: string;
/** Email content with verification link placeholder */
TemplateContent: string;
/** Success redirection URL */
SuccessRedirectionURL: string;
/** Failure redirection URL */
FailureRedirectionURL: string;
}
interface CreateCustomVerificationEmailTemplateCommandOutput {
$metadata: ResponseMetadata;
}
/**
* Gets a custom verification email template
* @param input - Template name to retrieve
* @returns Promise with template definition
*/
interface GetCustomVerificationEmailTemplateCommandInput {
/** Template name to retrieve */
TemplateName: string;
}
interface GetCustomVerificationEmailTemplateCommandOutput {
/** Template name */
TemplateName?: string;
/** Sender email address */
FromEmailAddress?: string;
/** Email subject */
TemplateSubject?: string;
/** Email content */
TemplateContent?: string;
/** Success redirection URL */
SuccessRedirectionURL?: string;
/** Failure redirection URL */
FailureRedirectionURL?: string;
$metadata: ResponseMetadata;
}
/**
* Lists custom verification email templates
* @param input - Optional pagination parameters
* @returns Promise with template list
*/
interface ListCustomVerificationEmailTemplatesCommandInput {
/** Token for pagination */
NextToken?: string;
/** Maximum number of results */
MaxResults?: number;
}
interface ListCustomVerificationEmailTemplatesCommandOutput {
/** List of custom verification templates */
CustomVerificationEmailTemplates?: CustomVerificationEmailTemplate[];
/** Token for next page of results */
NextToken?: string;
$metadata: ResponseMetadata;
}
interface CustomVerificationEmailTemplate {
/** Template name */
TemplateName?: string;
/** Sender email address */
FromEmailAddress?: string;
/** Email subject */
TemplateSubject?: string;
/** Success redirection URL */
SuccessRedirectionURL?: string;
/** Failure redirection URL */
FailureRedirectionURL?: string;
}interface Template {
/** Unique template name */
TemplateName: string;
/** Subject line with variable placeholders */
Subject?: string;
/** Plain text content with variable placeholders */
TextPart?: string;
/** HTML content with variable placeholders */
HtmlPart?: string;
}type BulkEmailStatus =
| "Success"
| "MessageRejected"
| "MailFromDomainNotVerified"
| "ConfigurationSetDoesNotExist"
| "TemplateDoesNotExist"
| "AccountSuspended"
| "AccountThrottled"
| "AccountDailyQuotaExceeded"
| "InvalidSendingPoolName"
| "AccountSendingPaused"
| "ConfigurationSetSendingPaused"
| "InvalidParameter"
| "TransientFailure"
| "Failed";class TemplateDoesNotExistException extends SESServiceException {
name: "TemplateDoesNotExistException";
}
class InvalidTemplateException extends SESServiceException {
name: "InvalidTemplateException";
}
class AlreadyExistsException extends SESServiceException {
name: "AlreadyExistsException";
}
class CustomVerificationEmailTemplateAlreadyExistsException extends SESServiceException {
name: "CustomVerificationEmailTemplateAlreadyExistsException";
}
class CustomVerificationEmailInvalidContentException extends SESServiceException {
name: "CustomVerificationEmailInvalidContentException";
}
class MissingRenderingAttributeException extends SESServiceException {
name: "MissingRenderingAttributeException";
}
class InvalidRenderingParameterException extends SESServiceException {
name: "InvalidRenderingParameterException";
}Complete Template Lifecycle Example:
import {
SESClient,
CreateTemplateCommand,
TestRenderTemplateCommand,
SendBulkTemplatedEmailCommand,
ListTemplatesCommand
} from "@aws-sdk/client-ses";
const client = new SESClient({ region: "us-east-1" });
// 1. Create template
const template = {
TemplateName: "ProductUpdate",
Subject: "New features in {{product_name}}!",
TextPart: `Hi {{customer_name}},
We've added exciting new features to {{product_name}}:
{{#features}}
- {{feature_name}}: {{feature_description}}
{{/features}}
Try them out at {{product_url}}
Best regards,
{{company_name}}`,
HtmlPart: `<h1>New features in {{product_name}}!</h1>
<p>Hi {{customer_name}},</p>
<p>We've added exciting new features:</p>
<ul>
{{#features}}
<li><strong>{{feature_name}}</strong>: {{feature_description}}</li>
{{/features}}
</ul>
<p><a href="{{product_url}}">Try them out now</a></p>
<p>Best regards,<br>{{company_name}}</p>`,
};
await client.send(new CreateTemplateCommand({ Template: template }));
// 2. Test rendering
const testData = {
customer_name: "Alice",
product_name: "DataViz Pro",
company_name: "Acme Corp",
product_url: "https://acme.com/dataviz",
features: [
{
feature_name: "Real-time Charts",
feature_description: "Live updating visualizations"
},
{
feature_name: "Export Options",
feature_description: "PDF and PNG export capabilities"
},
],
};
const rendered = await client.send(new TestRenderTemplateCommand({
TemplateName: "ProductUpdate",
TemplateData: JSON.stringify(testData),
}));
console.log("Template renders correctly:", rendered.Subject);
// 3. Send to customers
const bulkResponse = await client.send(new SendBulkTemplatedEmailCommand({
Source: "updates@acme.com",
Template: "ProductUpdate",
DefaultTemplateData: JSON.stringify({
product_name: "DataViz Pro",
company_name: "Acme Corp",
product_url: "https://acme.com/dataviz",
}),
Destinations: [
{
Destination: { ToAddresses: ["alice@customer1.com"] },
ReplacementTemplateData: JSON.stringify({
customer_name: "Alice",
features: testData.features,
}),
},
{
Destination: { ToAddresses: ["bob@customer2.com"] },
ReplacementTemplateData: JSON.stringify({
customer_name: "Bob",
features: testData.features,
}),
},
],
}));
console.log("Bulk email sent successfully");