本文介绍了反应无法使用SendGrid发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Reaction应用程序中写入电子邮件详细信息
使用电子邮件数据(收件人、标题、内容等)向您的服务器终结点发送POST请求(例如/sendmail)
接收服务器中的电子邮件数据并将其发送到SendGrid API
我正在使用Reaction发送电子邮件:
const sgMail = require('@sendgrid/mail'); sgMail.setApiKey(process.env.REACT_APP_SENDGRID); const msg = { to: 'test@example', from: 'test@example', 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);但我收到以下错误:
Access to fetch at 'api.sendgrid/v3/mail/send' from origin 'localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: The 'Access-Control-Allow-Origin' header has a value 'sendgrid.api-docs.io' that is not equal to the supplied origin. Have the server send the header with a valid value, or, if an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.我如何修复它?非常感谢!
SendGrid推荐答案不允许您在浏览器中使用Java脚本直接发送电子邮件。
您需要设置服务器并使用服务器发送电子邮件(使用您最喜欢的后端框架/语言、Node.js、php、Java等)。
发送邮件的步骤如下:
以下是有关其CORS策略的官方SendGrid文档:sendgrid/docs/for-developers/sending-email/cors/
更多推荐
反应无法使用SendGrid发送电子邮件
发布评论