2
私はMEAN STACKでプロジェクトを開発中で、私は自分のアプリケーションで多くの電子メールを送信する必要があります。 私は電子メールテンプレートをすべて別々の電子メールテンプレートとして作成しましたが、電子メールテンプレートに共通のヘッダーとフッターを作成したいと考えています。Nodejs - 電子メールテンプレートを動的にする
Route.js
router
.route('/api/user/register')
.post(
//for get email template
var fs = require("fs");
var message = fs.readFileSync(basePath + "app/client/views/layout/registerEmailTemplate.html").toString();
.......
);
router
.route('/api/user/forgotpassword')
.post(
//for get email template
var fs = require("fs");
var message = fs.readFileSync(basePath + "app/client/views/layout/resetPasswordEmailTemplate.html").toString();
.......
);
router
.route('/api/user/accountActivation')
.post(
//for get email template
var fs = require("fs");
var message = fs.readFileSync(basePath + "app/client/views/layout/accountActivationEmailTemplate.html").toString();
.......
);
registerEmailTemplate.html
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
<title>Whizbite</title>
<style>
here all common css
</style>
</head>
<body style="margin:0px;padding:0px">
here registratin html code
</body>
</html>
resetPasswordEmailTemplate.html
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
<title>Whizbite</title>
<style>
here all common css
</style>
</head>
<body style="margin:0px;padding:0px">
here resetpassword html code
</body>
</html>
accountActivationEmailTemplate.html
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
<title>Whizbite</title>
<style>
here all common css
</style>
</head>
<body style="margin:0px;padding:0px">
here account activation html code
</body>
</html>
依存性
"express" => "version": "4.13.4",
"mongoose" => "version": "4.4.4",
"mongodb" => "version": "2.4.9",
"OS" => "ubuntu 14.04 lts 32bit",
すべてのボディは、私が動的に電子メールに名前を挿入していたとき、私はHTMLに書式設定文字列を使用する動的電子メールテンプレートに