使用emailjs添加电子邮件模板
我有以下几行,这是我试过的,它工作正常,但我想加载一个模板来绘制内容,我怎样才能附加一个文件作为电子邮件的内容显示? 这里有我所拥有的:
attachment:[{data: req.__({ phrase: 'Please click this link to reset your password: https://website.com/reset/%s', locale: locale}, user.uuid), alternative:true}]
我怎样才能加载一个path来读取像HTML文件的内容?
我可以使用添加以下行的模板:
var forgotTemplate = fs.readFileSync('../public/mailplates/forgot');
接着:
attachment: [{data: forgotTemplate, alternative:true}]
无论如何,我需要适应“哈希”更改密码,我怎么可以添加脚本行内部或至less一个string?
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); });
最后, 解决scheme是与玉,我补充说:
var jade = require('jade');
接着:
var forgotTemplate = jade.renderFile('../public/mailplates/forgot.jade', {userRecover: userInfoRecover});
Jade模板必须显示如下所示:
doctype html html head title = forgot password body h1 this works a(href='#{ userRecover }') link