【问题标题】:Possible to send an email from SendGrid & React.js without a back-end?可以在没有后端的情况下从 SendGrid 和 React.js 发送电子邮件吗?
【发布时间】:2020-02-17 15:56:45
【问题描述】:

我有一个 React.js 应用程序,我在一个 cPanel 上托管,该应用程序不允许在应用程序中使用后端。想知道我是否可以在没有后端的情况下让 sendgrid 工作?以前有人让这个工作吗?

我目前收到以下错误:

Access to fetch at 'https://api.sendgrid.com/v3/mail/send' from origin ' 
    https://angelospizzaharvard.com' 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 'https://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.
    Navbar.js:427 TypeError: Failed to fetch

【问题讨论】:

  • 这绝对是可能的,但实际上根本不推荐,因为您需要将您的电子邮件服务器身份验证凭据暴露给前端,这是一个很大的禁忌
  • 比尔,如果我将电子邮件服务器登录凭据隐藏在 .env 文件中会怎样?
  • @Eric K。它仍然会被公开,因为它需要随请求一起发送。
  • @EricK.env 文件仅将秘密值保留在您的 git 存储库之外,它们仍然暴露在生产中的前端

标签: reactjs sendgrid


【解决方案1】:

从这个链接sendgrid docs看来,它似乎只能从后端服务器调用。

【讨论】:

  • 谢谢,Shmili。您是否知道任何其他技术可能允许从仅前端应用程序中的表单发送电子邮件?
  • @Eric K. 我以前使用过formspree.io,但是免费版本有一些严重的限制。 (它在提交时重定向用户)。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-03-05
  • 1970-01-01
  • 2015-11-09
  • 2016-11-13
  • 2015-12-12
  • 1970-01-01
  • 2012-01-06
相关资源
最近更新 更多