Skip to content

Commit

Permalink
JavaScript (v3): Add SES SendRawEmail example using nodemailer.
Browse files Browse the repository at this point in the history
  • Loading branch information
cpyle0819 committed Aug 21, 2023
1 parent d9c57fb commit 000847f
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 1,113 deletions.
18 changes: 18 additions & 0 deletions .doc_gen/metadata/ses_metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,24 @@ ses_SendBulkTemplatedEmail:
- ses.JavaScript.email.sendBulkTemplatedEmailV3
services:
ses: {SendBulkTemplatedEmail}
ses_SendRawEmail:
title: Send a raw email with &SES; using an &AWS; SDK
title_abbrev: Send raw email
synopsis: send a raw email with &SES;.
category:
languages:
JavaScript:
versions:
- sdk_version: 3
github: javascriptv3/example_code/ses
sdkguide:
excerpts:
- description: Use <ulink url="https://nodemailer.com/transports/ses/">nodemailer</ulink> to send an email
with an attachment.
snippet_tags:
- javascript.v3.ses.attachment
services:
ses: {SendRawEmail}
ses_SendTemplatedEmail:
title: Send templated email with &SES; using an &AWS; SDK
title_abbrev: Send templated email
Expand Down
4 changes: 3 additions & 1 deletion javascriptv3/example_code/ses/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
"integration-test": "vitest run **/*.integration.test.js"
},
"dependencies": {
"@aws-sdk/client-ses": "^3.215.0"
"@aws-sdk/client-ses": "^3.215.0",
"nodemailer": "^6.9.4"
},
"devDependencies": {
"@types/nodemailer": "^6.4.9",
"vitest": "^0.25.2"
}
}
55 changes: 55 additions & 0 deletions javascriptv3/example_code/ses/src/send-with-attachments.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

import {fileURLToPath} from "url";

// snippet-start:[javascript.v3.ses.attachment]
import sesClientModule from "@aws-sdk/client-ses";
/**
* nodemailer wraps the SES SDK and calls SendRawEmail. Use this for more advanced
* functionality like adding attachments to your email.
*
* https://nodemailer.com/transports/ses/
*/
import nodemailer from "nodemailer";

Check failure on line 16 in javascriptv3/example_code/ses/src/send-with-attachments.js

View workflow job for this annotation

GitHub Actions / lint

Unable to resolve path to module 'nodemailer'

/**
* @param {string} from An Amazon SES verified email address.
* @param {*} to An Amazon SES verified email address.
*/
export const sendEmailWithAttachments = (
from = "[email protected]",
to = "[email protected]"
) => {
const ses = new sesClientModule.SESClient({});
const transporter = nodemailer.createTransport({

Check failure on line 27 in javascriptv3/example_code/ses/src/send-with-attachments.js

View workflow job for this annotation

GitHub Actions / lint

Unsafe member access .createTransport on an `any` value
SES: {ses, aws: sesClientModule},
});

return new Promise((resolve, reject) => {
transporter.sendMail(

Check failure on line 32 in javascriptv3/example_code/ses/src/send-with-attachments.js

View workflow job for this annotation

GitHub Actions / lint

Unsafe member access .sendMail on an `any` value
{
from,
to,
subject: "Hello World",
text: "Greetings from Amazon SES!",
attachments: [{content: "Hello World!", filename: "hello.txt"}],
},
(err, info) => {
if (err) {
reject(err);
} else {
resolve(info);
}
}
);
});
};
// snippet-end:[javascript.v3.ses.attachment]

// Invoke main function if this file was run directly.
if (process.argv[1] === fileURLToPath(import.meta.url)) {
sendEmailWithAttachments();
}
Loading

0 comments on commit 000847f

Please sign in to comment.