2016-03-15 260 views
1

我有以下幾行,這是我試過的,它工作正常,但我想加載一個模板來繪製內容,我如何附加一個文件作爲顯示爲電子郵件的內容?這裏就是我所擁有的:添加電子郵件的模板與電子郵件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文件之類的內容?

回答

1

最後,解決方案是玉,我補充一下:

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 
1

我可以使用模板添加此行:

var forgotTemplate = fs.readFileSync('../public/mailplates/forgot'); 

然後:

attachment: [{data: forgotTemplate, alternative:true}] 

無論如何,我需要適應更改密碼的「散列」,我怎麼能添加腳本行內部或至少一個字符串?

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); }); 
+0

whe你是否附加文件? html模板?這不是解決方案。 – dlcod