我正在使用 Resend 为我的 next.js 项目中的联系表单发送电子邮件。我正在填写联系表单并提交,但我没有收到电子邮件,也没有看到“重新发送”登录失败或成功。但是,我在 Vercel 部署日志中收到一条 siccesful 消息。请记住,我在本地主机中收到电子邮件,但在部署后却没有收到电子邮件。我该如何解决?
import { NextApiRequest, NextApiResponse } from 'next';
import { Resend } from 'resend';
const resend = new Resend(process.env.RESEND_API_KEY);
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
if (req.method !== 'POST') {
return res.status(405).json({ message: 'Method Not Allowed' });
}
try {
const formData = req.body;
console.log('Received form data:', formData);
resend.emails.send({
from: '[email protected]',
to: '[email protected]',
subject: 'New Contact Form Message',
html: `<p>This is an Email to DWS from Contact Form. the name of the person is: ${formData.name}, the referrer is ${formData.referrer}, and the email is ${formData.email}. The message is: (${formData.message})</p>`
});
// if resend is not sending the email, throw error
if (!resend) {
console.error('Error sending message');
return res.status(500).json({ message: 'Internal Server Error' });
}
console.log('Message sent successfully');
return res.status(200).json({ success: true });
} catch (error) {
console.error('Error sending message:', error);
return res.status(500).json({ message: 'Internal Server Error' });
}
}