我有以下几行,这是我尝试的,它工作正常,但我想加载一个模板用于绘制内容,我如何附加文件显示为电子邮件的内容?这就是我所拥有的:
attachment:[{data: req.__({ phrase: 'Please click this link to reset your password: https://website.com/reset/%s', locale: locale}, user.uuid), alternative:true}]
如何加载路径以从HTML文件中读取内容?
答案 0 :(得分:1)
我可以使用添加以下行的模板:
var forgotTemplate = fs.readFileSync('../public/mailplates/forgot');
然后:
attachment: [{data: forgotTemplate, alternative:true}]
无论如何,我需要适应" hash"要更改密码,我如何在里面添加脚本行或至少在字符串中添加?
答案 1 :(得分:1)
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); });
答案 2 :(得分:1)
最后,一个解决方案与Jade,我添加:
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