首页 > 解决方案 > 构建电子邮件并将其发送出去

问题描述

我们的前端使用带有 Java 后端的 React。我们希望让用户能够将页面上的信息通过电子邮件发送给其他人。环顾四周,我可以看到有些人使用 React 作为电子邮件模板,他们会生成 HTML,然后将其发送到后端(https://assertible.com/blog/creating-email-templates-with -react-components)(https://building.lang.ai/how-to-build-emails-with-react-fcf941b125d1),但我想知道这是否是正确的方法。

哪种方法会更好?

  1. 当点击 email 按钮时,将 react 组件与 props 一起转换为 HTML 并发送到后端发送出去。从前端传出的 json 看起来像:
{ 
 to: <>,
 from: <>,
 subject: <>,
 body: <where the html would go>,
 additionalComments: <>
}
  1. 单击电子邮件按钮时,我们发送会将适当的信息从前端发送到后端,后端将生成电子邮件。从前端传出的 json 看起来像:
{
 to: <>,
 from: <>,
 subject: <>,
 foo: <>,
 bar: <>,
 additionalComments: <>
}

我倾向于第一种方法,但我不确定标准是什么。第一种方法允许我重用我在 React 中已有的组件,并将后端简单地用作电子邮件服务器。第二种方法可以让我们保留更多信息,也无需发送 html。

标签: javahtmlreactjsemail

解决方案


推荐阅读