我使用此guide作为创建此服务的api的参考。用户只需输入名称,电子邮件,电话和描述,然后将其发送到gmail电子邮件中。
我正在使用Zeit Now创建api,这是用TypeScript编写的代码:
import sendGrid from "@sendgrid/mail";
import { Nextapirequest,Nextapiresponse } from "next";
import { IEmailValues } from "../../types/IEmailValues";
export default (req: Nextapirequest,res: Nextapiresponse) => {
const { name,email,telephone,description }: IEmailValues = req.body;
sendGrid.setapiKey(process.env.SENDGRID_API_KEY);
const content = {
to: "rmcarga.logistica@gmail.com",// carga logistica email
from: email,subject: `${name} requiere de un servicio.`,html: `
Nombre: ${name}<br>
Email: ${email}<br>
Teléfono: ${telephone}<br>
<p>${description}</p>
`
};
try {
sendGrid.send(content);
res.status(200).send({ response: true });
} catch (error) {
console.error(error);
res.status(400).send({ response: false });
}
};
here's完整的代码。
在开发中,效果很好,这是响应:
但是在生产中没有:
这是我在生产中使用的网站:https://carga-logistica.now.sh/
我该如何解决?谢谢。