Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
var AWS = require("aws-sdk");
var simpleParser = require("mailparser").simpleParser;
var s3 = new AWS.S3();
exports.handler = async (event, context, callback) => {
console.log("Invoked Lambda");
const mail = event.Records[0].ses.mail;
console.log("Mail");
console.log(JSON.stringify(mail));
var getParams = {
Bucket: "disposible-mails-bucket",
Key: "awesome_crypto_me/" + mail.messageId,
};
let emailFromS3 = await s3.getObject(getParams).promise();
let parsedEmail = await simpleParser(emailFromS3.Body);
console.log("parsedEmail Subject: " + parsedEmail.subject);
console.log("parsedEmail Body: " + parsedEmail.textAsHtml);
callback(null);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment