Sendinblue未在Vercel上进行生产



通常的情况是,在开发中一切都很好,但在生产中却没有明显的原因。我在Vercel上托管了一个NextJS应用程序。

按照另一个StackOverflow线程的建议,我尝试在代码中添加异步等待,但我仍然无法实现。我在Vercel中添加了Sendinblue API键作为环境变量。这是我在api文件夹中的contact.js:

export default async function (req, res) {
require("dotenv").config();
const Sib = require("sib-api-v3-sdk");
const client = Sib.ApiClient.instance;
const apiKey = client.authentications["api-key"];
apiKey.apiKey = process.env.SendinBlueApiKey;
const tranEmailApi = new Sib.TransactionalEmailsApi();
const sender = {
email: req.body.email,
};
const receivers = [
{ email: "example@example.com" },
];
await new Promise((resolve, reject) => {
tranEmailApi
.sendTransacEmail({
sender,
to: receivers,
subject: `${req.body.service} from ${req.body.name}`,
textContent: req.body.message + " | Sent from: " + req.body.email,
htmlContent: `<div>${req.body.message}</div><p>Sent from:
${req.body.name} , 
${req.body.email}</p>`,
})
.then(res.status(200).send())
.catch(console.log);
});
}

我遇到了同样的问题,它把我逼上了墙。替换此:

await new Promise((resolve, reject) => {
tranEmailApi
.sendTransacEmail(...)
.then(res.status(200).send())
.catch(console.log);;
}

用这个

const emailResult = await tranEmailApi.sendTransacEmail(...);

我认为问题在于,否则vercel函数会在sendinblueapi调用返回之前完成。

相关内容

  • 没有找到相关文章

最新更新