dlcod
dlcod

Reputation: 31

Add a template for emails with emailjs

I have the following lines, This is what I tried, and it works fine but I want to load a template for drawing the content inside, how can I attach a file for being displayed as a content of the email? Here comes what I have:

attachment:[{data: req.__({ phrase: 'Please click this link to reset your password: https://website.com/reset/%s', locale: locale}, user.uuid), alternative:true}]

How can I load a path to read the content from something like an HTML file?

Upvotes: 1

Views: 4431

Answers (3)

dlcod
dlcod

Reputation: 31

Finally, a solution is with Jade, i add:

var jade = require('jade');

and then:

var forgotTemplate = jade.renderFile('../public/mailplates/forgot.jade', {userRecover: userInfoRecover});

The Jade template must display something like this:

doctype html
html
    head
        title = forgot password
    body
        h1 this works
        a(href='#{ userRecover }') link

Upvotes: 1

Dia Sarkar
Dia Sarkar

Reputation: 313

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

Upvotes: 1

dlcod
dlcod

Reputation: 31

I can use a template adding this lines:

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

and then:

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

Anyway, I need to fit the "hash" for change the password, how can i add a script line inside or at least a string?

Upvotes: 1

Related Questions