-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JavaScript (v3): Add SES SendRawEmail example using nodemailer.
- Loading branch information
Showing
4 changed files
with
76 additions
and
1,113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
javascriptv3/example_code/ses/src/send-with-attachments.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
|
||
/** | ||
* @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({ | ||
SES: {ses, aws: sesClientModule}, | ||
}); | ||
|
||
return new Promise((resolve, reject) => { | ||
transporter.sendMail( | ||
{ | ||
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(); | ||
} |
Oops, something went wrong.