我有一个简单的 vuetify 联系表格,我想通过电子邮件发送此表格。我曾尝试使用 amethod发送电子邮件,但它不起作用,因为它在客户端。所以我遇到了 CORS 问题。
这是我的代码:
async send() {
if (this.$refs.form.validate()) {
try {
const sgMail = require("@sendgrid/mail");
sgMail.setApiKey(process.env.SENDGRID_API_KEY);
const msg = {
to: "test@example.com",
from: "me@mydomain.com",
subject: "Sending with SendGrid is Fun",
text: "and easy to do anywhere, even with Node.js",
html: "<strong>and easy to do anywhere, even with Node.js</strong>"
};
sgMail.send(msg);
}
}
}
是否需要 Express(或其他后端)?有没有办法使用中间件让它工作?
编辑
显然,这是不可能的:https ://github.com/sendgrid/sendgrid-nodejs/issues/730