我想插入一个HTML文件模板,用于随节点发送的电子邮件。
当我使用下面的代码时,我收到此错误...
(function (exports, require, module, __filename, __dirname) { <!doctype html>
有什么建议吗?
var template = require('../../views/email-template.js');
var htmlAll = _.template(template)(contactinfo[0]);
var data = {
from: company@example.com,
to: email,
subject: 'Your Order Confirmation',
html: htmlAll
电子邮件template.js
<!doctype html>
<html>
<head>
<meta name="viewport" content="width=device-width">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Email</title>
<style media="all" type="text/css">
// . . .
<table>
// . . .
<td><%= firstName %> <%= lastName %>
<br><%= company %>
<br><%= address %>
<br><%= city %>, <%= state.code %> <%= zip %>
<br><%= email %>
<br><%= phone %>
</td>
</tr>
</table>
// . . .
答案 0 :(得分:1)
您无法通过nodejs require
使用fs
模块
var fs = require('fs')
var template = fs.readFileSync('../../views/email-template.js').toString();
var htmlAll = _.template(template)(contactinfo[0]);
最好缓存fs.readFileSync
结果以便持续使用