如何使用ReactJS和SendGrid发送电子邮件?

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

我已在SendGrid上设置和帐户。我已经得到了API密钥和Node.js方法。我正在创建一个反应js的网络应用程序。我想通过SendGrid发送电子邮件。我找不到任何解决办法。请用一个例子帮助我回答我的问题。

推荐答案//Form.js class Form extends React.Component { constructor() { super(); this.handleSubmit = this.handleSubmit.bind(this); } handleSubmit(event) { event.preventDefault(); const data = new FormData(event.target); fetch('/api/form-submit-url', { method: 'POST', body: data, }); } render() { return ( <form onSubmit={this.handleSubmit}> <label htmlFor="username">Enter username</label> <input id="username" name="username" type="text" /> <label htmlFor="email">Enter your email</label> <input id="email" name="email" type="email" /> <label htmlFor="birthdate">Enter your birth date</label> <input id="birthdate" name="birthdate" type="text" /> <button>Send data!</button> </form> ); } } //index.js const sgMail = require('@sendgrid/mail'); sgMail.setApiKey(process.env.SENDGRID_API_KEY); 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);

更多推荐

如何使用ReactJS和SendGrid发送电子邮件?

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

发布评论

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

>www.elefans.com

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