【以下的问题经过翻译处理】 我收到一个500错误("message":"Failed to send email")。以下是在浏览器中显示的内容。

这是我在网站上使用的 JS:
const submitBtn = document.getElementById('submit-btn'), //submit form button
htmlForm = document.getElementById('contact-form'), //contact form
endpoint = "https://xxxxxxxxxx.execute-api.us-west-2.amazonaws.com/Email"; //call lambda function
submitBtn.addEventListener('click', () => {
const formData = new FormData(htmlForm), // capture form data
urlEncodedData = new URLSearchParams(); // format data
for (const pair of formData.entries()) {
urlEncodedData.append(pair[0], pair[1]);
}
htmlForm.requestSubmit(); // only sends if form is valid
fetch(endpoint, {
method: "post",
body: urlEncodedData,
headers: {
"Content-Type": "application/x-www-form-urlencoded"
}
}).then(response => {
if (response.ok) {
resetForm();
contactDialog.close();
} else {
throw new Error('HTTP error. Status: ${response.status}');
}
}).catch(error => {
console.log('Something is wrong *shrugs*');
});
});
htmlForm.addEventListener('submit', (event) => {
event.preventDefault(); // prevents submitting to self (page)
});
当前的 Lambda 代码:
const AWS = require('aws-sdk'),
ses = new AWS.SES(),
querystring = require('querystring');
exports.handler = async (event) => {
const formData = querystring.parse(event.body),
toAddress = formData.toAddress,
message = formData.message,
replyTo = formData.replyTo,
sourceEmail = formData.sourceEmail,
subject = formData.subject;
// Construct the email message
const emailParams = {
Destination: {
ToAddresses: [`${toAddress}`]
},
Message: {
Subject: {
Data: `${subject}`
},
Body: {
Text: {
Data: `${message}`
}
}
},
ReplyToAddresses: [`${replyTo}`],
Source: `${sourceEmail}`
};
// Send the email using SES
try {
await ses.sendEmail(emailParams).promise();
return {
statusCode: 200,
body: JSON.stringify({ message: 'Email sent successfully' })
};
} catch (err) {
console.log(err);
return {
statusCode: 500,
body: JSON.stringify({ message: 'Failed to send email' })
};
}
};