反应无法使用SendGrid发送电子邮件

编程入门 行业动态 更新时间:2024-10-22 04:51:44
本文介绍了反应无法使用SendGrid发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用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等)。

发送邮件的步骤如下:

  • 在Reaction应用程序中写入电子邮件详细信息
  • 使用电子邮件数据(收件人、标题、内容等)向您的服务器终结点发送POST请求(例如/sendmail)
  • 接收服务器中的电子邮件数据并将其发送到SendGrid API
  • 以下是有关其CORS策略的官方SendGrid文档:sendgrid/docs/for-developers/sending-email/cors/

    更多推荐

    反应无法使用SendGrid发送电子邮件

    本文发布于:2023-11-06 06:36:52,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1562958.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:发送电子邮件   SendGrid

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!