Skip to content

Instantly share code, notes, and snippets.

@faishal
Last active November 10, 2023 20:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save faishal/5bac1e0ea3b5109baf26cebef7b43bef to your computer and use it in GitHub Desktop.
Save faishal/5bac1e0ea3b5109baf26cebef7b43bef to your computer and use it in GitHub Desktop.
RCPT TO AWS SES Example using nodemailer
import nodemailer from "nodemailer";
import { defaultProvider } from "@aws-sdk/credential-provider-node";
import sesClient from "@aws-sdk/client-ses";
async function wrapedSendMail(mailOptions){
return new Promise((resolve,reject)=>{
const ses = new sesClient.SES({
apiVersion: "2010-12-01",
defaultProvider,
});
// create Nodemailer SES transporter
let transporter = nodemailer.createTransport({
SES: { ses, aws: sesClient },
});
transporter.sendMail(mailOptions, function(error, info){
if (error) {
console.log("error is "+error);
resolve(false); // or use rejcet(false) but then you will have to handle errors
} else {
console.log('Email sent: ' + info.response);
resolve(true);
}
});
});
}
export const handler = async (event) => {
let message = {
envelope: {
from: 'test@faish.al',
to: ['rcptto@faish.al']
},
raw: {
path: './test.eml'
}
};
let resp = await wrapedSendMail(message);
console.log(resp);
return;
}
MIME-Version: 1.0
Date: Thu, 20 Jan 2022 15:47:27 -0800
Message-ID: <rK5g@mail.gmail.com>
Subject: Test Email
From: Faishal Saiyed <me@faish.al>
To: Faishal Saiyed <to@faish.al>
Content-Type: multipart/alternative; boundary="00000000000000f4da05d60c2025"
--00000000000000f4da05d60c2025
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Test text email
--00000000000000f4da05d60c2025
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div>Test HTML email <br></div></div>
--00000000000000f4da05d60c2025--
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment