Feras Odeh
Feras Odeh

Reputation: 9306

New line in node.js mailer template

I'm using node.js mailer module to send email from node server. I used template file for that but I got all spaces trimmed when the message was sent. I tried to add '\n' at the end line of the template but it doesn't work also. Here is an example of template file:

Hi {{username}},\\n

Thanks for creating an account with us

I tried \n and \n , nothing all doesn't work. Any help?

Thanks,

Upvotes: 3

Views: 8109

Answers (2)

SuperStar518
SuperStar518

Reputation: 2885

nodemailer supports two types of templates, i.e. text and html (or templateFn() - case of loopback).

The option text is used for email clients which don't support HTML rendering so that \n should be used in this option for a new line.

On the contrary, you should swap \n with <br> in the option html.

Hope this would help you.

Upvotes: 6

Tronix117
Tronix117

Reputation: 1985

It's a known behavior, mustache is made to work with HTML templates, in HTML, new lines will be contracted as one space only.

You can try doing something like {{new_line}} instead your \\n, and define new_line: "\n\xA0" in your datas. \xA0 is the non-breakable space, it can separate line if you want to make two new lines.

An other solution is to not use the template, but just get the content of the file as text with fs.readFileSync(filename) and use a regexp to replace {{xxx}} by an object content.

Upvotes: 1

Related Questions