添加电子邮件的模板与电子邮件js
问题描述:
我有以下几行,这是我试过的,它工作正常,但我想加载一个模板来绘制内容,我如何附加一个文件作为显示为电子邮件的内容?这里就是我所拥有的:添加电子邮件的模板与电子邮件js
attachment:[{data: req.__({ phrase: 'Please click this link to reset your password: https://website.com/reset/%s', locale: locale}, user.uuid), alternative:true}]
如何加载一个路径来读取HTML文件之类的内容?
答
最后,解决方案是玉,我补充一下:
var jade = require('jade');
然后:
var forgotTemplate = jade.renderFile('../public/mailplates/forgot.jade', {userRecover: userInfoRecover});
玉模板必须是这样显示的东西:
doctype html
html
head
title = forgot password
body
h1 this works
a(href='#{ userRecover }') link
答
我可以使用模板添加此行:
var forgotTemplate = fs.readFileSync('../public/mailplates/forgot');
然后:
attachment: [{data: forgotTemplate, alternative:true}]
无论如何,我需要适应更改密码的“散列”,我怎么能添加脚本行内部或至少一个字符串?
答
var email = require("./path/to/emailjs/email");
var server = email.server.connect({
user: "username",
password:"password",
host: "smtp.your-email.com",
ssl: true
});
var message = {
text: "... ",
from: "...",
to: "...",
subject: "testing emailjs",
attachment:
[
{data:"<html>i <i>hope</i> this helps</html>", alternative:true},
{path:"path/to/file.zip", type:"application/zip", name:"renamed.zip"}
]
};
// send the message and get a callback with an error or details of the message that was sent
server.send(message, function(err, message) { console.log(err || message); });
whe你是否附加文件? html模板?这不是解决方案。 – dlcod