使用 Reactjs 发送电子邮件[已关闭]

问题描述 投票:0回答:1

我正在尝试使用一个 API 通过 JavaScript 发送电子邮件,它称为 SmptJs。当集成到一个简单的 HTML 文件中时,该 API 工作得很好,但我不知道如何将它集成到一个 ReactJs 组件中!

这里是 API 链接和文档:https://smtpjs.com/

我首先在 HTML 页面中尝试过,如下所示:code of html file

它成功了,我收到了电子邮件。 但我想在我的 React 组件中添加 API,特别是当我在表单中单击“提交”时,但出现错误,我认为它与 ReactJs 语法不兼容,这是图像:

code of react component

the error msg

javascript reactjs smtp
1个回答
2
投票

在此处查看带有示例的简单组件https://jsfiddle.net/92a68tmz/

您必须在项目的 public/index.html 或常规index.html 文件中包含 smtpjs 的标签,然后就可以像这样使用它了

 sendMail() {
     window.Email.send({
        SecureToken : "C973D7AD-F097-4B95-91F4-40ABC5567812",
        To : '[email protected]',
        From : "[email protected]",
        Subject : "This is the subject",
        Body : "And this is the body"
    }).then(
  message => alert(message)
);

在你的

onSubmit
中你直接使用这个

     const onSubmit = data => {
              window.Email.send({
                    SecureToken : "C973D7AD-F097-4B95-91F4-40ABC5567812",
                    To : data.email,
                    From : "[email protected]",
                    Subject : "This is the subject",
                    Body : "And this is the body" + data.firstname
                }).then(
                    message => alert(message)
      }

无需单独的电子邮件发送器组件。

© www.soinside.com 2019 - 2024. All rights reserved.