Last active
November 10, 2023 20:30
-
-
Save faishal/5bac1e0ea3b5109baf26cebef7b43bef to your computer and use it in GitHub Desktop.
RCPT TO AWS SES Example using nodemailer
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
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: '[email protected]', | |
to: ['[email protected]'] | |
}, | |
raw: { | |
path: './test.eml' | |
} | |
}; | |
let resp = await wrapedSendMail(message); | |
console.log(resp); | |
return; | |
} |
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
MIME-Version: 1.0 | |
Date: Thu, 20 Jan 2022 15:47:27 -0800 | |
Message-ID: <[email protected]> | |
Subject: Test Email | |
From: Faishal Saiyed <[email protected]> | |
To: Faishal Saiyed <[email protected]> | |
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