将文本插入带有来自其他文件的函数的html/css电子邮件中

发布于 2025-02-12 05:04:32 字数 1845 浏览 1 评论 0原文

我有一个HTML/CSS电子邮件模板,我想用它来向用户发送电子邮件,例如在注册,发送秘密代码和通用电子邮件之后欢迎的内容。

我需要用自定义文本“注入”此HTML模板,而不是当前包含的lorem ipsum。

我想制作一个JavaScript函数,将给定文本插入我的HTML模板中,这样我的电子邮件服务可以根据用户在我的节点应用程序中根据其电子邮件和自定义消息发送自定义电子邮件,因为某些事件被触发。

我在文件 generalcontact.html 中有一个html/css电子邮件,

我不确定 1 如何“导出”它,以便makeemail.js可以访问模板和模板和模板 2 如何格式化HTML电子邮件,以便它可以接受自定义输入文本。

我必须以某种方式将模板分配给变量吗?

任何帮助/指导将不胜感激,谢谢。

makeemail.js

const htmlTemplate = require("generalContact.html")

const makeEmail = (bodyText) => {
      // How can I access the HTML file and insert the above input into it?
      return emailWithTextInserted 
}

module.exports = makeEmail

GeneralContact.html

<!DOCTYPE html PUBLIC "-//W3C/...." "http://www.w3.org/.....">
<html xmlns="http://www.w3.org......">
  <head>
    <title></title>
  </head>
  <body>
    <center>
      <tr>
        <td>
          This is Photoshop's version of Lorem Ipsum. Proin gravida nibh vel
          velit auctor aliquet. Aenean sollicitudin, lorem quis bibendum auctor,
          nisi elit consequat ipsum, nec sagittis sem nibh id elit. Duis
          <a>
          sit amet nibh vulputate cursus a sit amet mauris.<br /><br />

          Mauris in erat justo. Nullam ac urna eu felis dapibus condimentum sit
          amet a augue. Sed non neque elit. Sed ut imperdiet nisi. Proin
          condimentum fermentum nunc. Etiam
          <a>
          erat sed fermentum feugiat, velit mauris egestas quam, ut aliquam
          massa nisl quis neque. Suspendisse in orci enim.
        </td>
      </tr>
    </center>
  </body>
</html>

I have a html/css e-mail template that I want to use to send users e-mails for things like welcoming after signing up, send secret codes, and general purpose e-mails.

I need to "inject" this html template it with custom text instead of the lorem ipsum it currently contains.

I want to make a javascript function that inserts given text into my html template, this way my e-mail service can send custom e-mail to users based on their e-mail and custom messages throughout my node app as certain events are triggered.

I have a html/css e-mail in the file generalContact.html

I am unsure of 1 how "export" it so that makeEmail.js has access to the template and 2 how to format the html email so it can accept custom input text.

Do I have to assign the template to a variable first somehow?

Any help/guidance would be appreciated, thank you.

makeEmail.js

const htmlTemplate = require("generalContact.html")

const makeEmail = (bodyText) => {
      // How can I access the HTML file and insert the above input into it?
      return emailWithTextInserted 
}

module.exports = makeEmail

generalContact.html

<!DOCTYPE html PUBLIC "-//W3C/...." "http://www.w3.org/.....">
<html xmlns="http://www.w3.org......">
  <head>
    <title></title>
  </head>
  <body>
    <center>
      <tr>
        <td>
          This is Photoshop's version of Lorem Ipsum. Proin gravida nibh vel
          velit auctor aliquet. Aenean sollicitudin, lorem quis bibendum auctor,
          nisi elit consequat ipsum, nec sagittis sem nibh id elit. Duis
          <a>
          sit amet nibh vulputate cursus a sit amet mauris.<br /><br />

          Mauris in erat justo. Nullam ac urna eu felis dapibus condimentum sit
          amet a augue. Sed non neque elit. Sed ut imperdiet nisi. Proin
          condimentum fermentum nunc. Etiam
          <a>
          erat sed fermentum feugiat, velit mauris egestas quam, ut aliquam
          massa nisl quis neque. Suspendisse in orci enim.
        </td>
      </tr>
    </center>
  </body>
</html>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无法回应 2025-02-19 05:04:32

如果您将GeneralContact.html a .js文件制作,或者将其放入当前.JS文件中,则可以使整个HTML平板一个变量使整个HTML平板一个变量。

let HTML = {
  get latest() {
    return `<!DOCTYPE html ...
    ...
    ${customInputText}...
    ...`
  }
}

然后在用户添加了与事件的内容添加该内容后更新customInputText变量。

var myInput = document.getElementById("customInputId");
myInput.addEventListener("change", function( 
  customInputText = this.value;
);

此时,您可以使用html.latest检索更新的HTML

If you instead make the generalContact.html a .js file, or just put it in the current .js file, then you can make the whole HTML slab one variable.

let HTML = {
  get latest() {
    return `<!DOCTYPE html ...
    ...
    ${customInputText}...
    ...`
  }
}

Then update the customInputText variable after the user has added that content with an event.

var myInput = document.getElementById("customInputId");
myInput.addEventListener("change", function( 
  customInputText = this.value;
);

At this point, you can retrieve the updated HTML using HTML.latest

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文