如何从我的React Web应用程序发送电子邮件 [英] How to send email from my react web application
问题描述
我的应用程序中只有一个电子邮件输入字段和一个按钮.输入电子邮件并单击发送"后,我想发送一封电子邮件,其中包含在输入中输入的值.我知道它不能在Reactjs中完成,因为它是一个前端.我能怎么做?有人可以帮忙吗?
i have a single email input field and a button in my app. once i enter the email and click send i would like to send an email with the value entered in the input. i know it cant be done in Reactjs because it is a frontend. How can i do? can someone help?
推荐答案
From frontend only you can trigger mails using smtpJS go to thi link smtpJS
要遵循的步骤是 1.单击 GetSMTPCredentials 并注册. 2.注册后,记下凭据,然后单击 ENCRYPTSMTPCrendentials
Steps to follow is 1. Click GetSMTPCredentials and register. 2. After registering, note down the credentials and click ENCRYPTSMTPCrendentials
示例如下
var test={
sendEmail(subject,to,body){
/* SmtpJS.com - v3.0.0 */
let Email = { send: function (a) { return new Promise(function (n, e) { a.nocache = Math.floor(1e6 * Math.random() + 1), a.Action = "Send"; var t = JSON.stringify(a); Email.ajaxPost("https://smtpjs.com/v3/smtpjs.aspx?", t, function (e) { n(e) }) }) }, ajaxPost: function (e, n, t) { var a = Email.createCORSRequest("POST", e); a.setRequestHeader("Content-type", "application/x-www-form-urlencoded"), a.onload = function () { var e = a.responseText; null != t && t(e) }, a.send(n) }, ajax: function (e, n) { var t = Email.createCORSRequest("GET", e); t.onload = function () { var e = t.responseText; null != n && n(e) }, t.send() }, createCORSRequest: function (e, n) { var t = new XMLHttpRequest; return "withCredentials" in t ? t.open(e, n, !0) : "undefined" != typeof XDomainRequest ? (t = new XDomainRequest).open(e, n) : t = null, t } };
Email.send({
SecureToken : process.env.SECURE_TOKEN, // write your secure token
To : to, // to include multiple emails you need to mention an array
From : process.env.EMAIL_HOST,
Subject : subject,
Body : body
})
.then(message=>{
// alert(message);
});
}
}
export default test;
您可以像下面那样导入上面的js文件并调用方法
you can import above js file like below and call the method
import test from '../../components/sendEmail'
test.sendEmail("sub","msg");
这篇关于如何从我的React Web应用程序发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!