Hi guys,
I have Lambda that sends Email
email was send and I received it correctly,
but it returns Internal server error,
and no errors in the CloudWatch.
Did someone had similar issue maybe?
Thank you
var AWS = require("aws-sdk");
var ses = new AWS.SES();
var {getTemplate} = require("./email-template.js")
var response = {
isBase64Encoded: false,
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
},
statusCode: 200,
body: JSON.stringify({ success: true, message: "Email sent successfully!" }),
};
const responseFailed = (error) => ({
isBase64Encoded: false,
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
},
statusCode: 200,
body: `{"result": { "success": false , "error": ${error}}}`,
});
exports.handler = function (event, context) {
console.log("Received event:", event);
var data = event.body ? JSON.parse(event.body) : event;
sendEmail(data, function (err, data) {
console.log("error", err);
if (err) {
console.log("Error sending email:", err);
return responseFailed;
} else {
console.log("Email sent successfully:", data);
}
context.done(err, null);
});
console.log("send finished");
return response;
};
function sendEmail(event, done) {
var senderEmail = event.senderEmail;
var company = event.company";
var email = event.email;
var name = event.name;
var message = event.message;
var receiverEmail = event.companyEmail;
var template = getTemplate({ name, email, body: message });
var params = {
Destination: {
ToAddresses: [receiverEmail],
},
Message: {
Body: {
Html: {
Data: template,
}
},
Subject: {
Data: event.subject,
Charset: "UTF-8",
},
},
Source: senderEmail,
};
ses.sendEmail(params, done);
}