AWS SDK または CLI SendBulkTemplatedEmailで を使用する - AWS SDK コードの例

Doc AWS SDK Examples リポジトリには、他にも SDK の例があります。 AWS GitHub

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

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

次の例は、SendBulkTemplatedEmail を使用する方法を説明しています。

JavaScript
SDK for JavaScript (v3)
注記

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

import { SendBulkTemplatedEmailCommand } from "@aws-sdk/client-ses"; import { getUniqueName, postfix, } from "@aws-doc-sdk-examples/lib/utils/util-string.js"; import { sesClient } from "./libs/sesClient.js"; /** * Replace this with the name of an existing template. */ const TEMPLATE_NAME = getUniqueName("ReminderTemplate"); /** * Replace these with existing verified emails. */ const VERIFIED_EMAIL_1 = postfix(getUniqueName("Bilbo"), "@example.com"); const VERIFIED_EMAIL_2 = postfix(getUniqueName("Frodo"), "@example.com"); const USERS = [ { firstName: "Bilbo", emailAddress: VERIFIED_EMAIL_1 }, { firstName: "Frodo", emailAddress: VERIFIED_EMAIL_2 }, ]; /** * * @param { { emailAddress: string, firstName: string }[] } users * @param { string } templateName the name of an existing template in SES * @returns { SendBulkTemplatedEmailCommand } */ const createBulkReminderEmailCommand = (users, templateName) => { return new SendBulkTemplatedEmailCommand({ /** * Each 'Destination' uses a corresponding set of replacement data. We can map each user * to a 'Destination' and provide user specific replacement data to create personalized emails. * * Here's an example of how a template would be replaced with user data: * Template: <h1>Hello {{name}},</h1><p>Don't forget about the party gifts!</p> * Destination 1: <h1>Hello Bilbo,</h1><p>Don't forget about the party gifts!</p> * Destination 2: <h1>Hello Frodo,</h1><p>Don't forget about the party gifts!</p> */ Destinations: users.map((user) => ({ Destination: { ToAddresses: [user.emailAddress] }, ReplacementTemplateData: JSON.stringify({ name: user.firstName }), })), DefaultTemplateData: JSON.stringify({ name: "Shireling" }), Source: VERIFIED_EMAIL_1, Template: templateName, }); }; const run = async () => { const sendBulkTemplateEmailCommand = createBulkReminderEmailCommand( USERS, TEMPLATE_NAME, ); try { return await sesClient.send(sendBulkTemplateEmailCommand); } catch (caught) { if (caught instanceof Error && caught.name === "MessageRejected") { /** @type { import('@aws-sdk/client-ses').MessageRejected} */ const messageRejectedError = caught; return messageRejectedError; } throw caught; } };
  • API の詳細については、「 API リファレンスSendBulkTemplatedEmail」の「」を参照してください。 AWS SDK for JavaScript