Created
January 26, 2022 00:31
-
-
Save edisdev/c35d7add520e1e6772a9f8fe31adecc2 to your computer and use it in GitHub Desktop.
Lambda Function For SES
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
const aws = require('aws-sdk') | |
const ses = new aws.SES() | |
exports.handler = async (event) => { | |
for (const record of event.Records) { | |
if (record.eventName === 'INSERT') { | |
const newData = record.dynamodb.NewImage | |
const name = newData.name.S | |
const email = newData.email.S | |
const message = newData.message.S | |
await ses | |
.sendEmail({ | |
Destination: { | |
ToAddresses: [process.env.SES_TO_EMAIL], | |
}, | |
Source: process.env.SES_FROM_EMAIL, | |
Message: { | |
Subject: { Data: 'X Sitesinden Mesajınız Var' }, | |
Body: { | |
Html: { | |
Data: ` | |
<div><b>Kimden: </b>${name}(${email})<div> | |
</br> | |
<div> | |
<b>Mesaj:</b> | |
<p>${message}</p> | |
</div> | |
` | |
} | |
}, | |
}, | |
}) | |
.promise() | |
} | |
} | |
return { status: 'done' } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment