1

I have this text here:

var text1 = '<p>Hey ' + rows[i].NAME + ', \n\nFrom our team here at Indera Technologies ...

I send it like this through html parameter in nodemailer transporter:

 var text1 = '<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"></head><body><p>Hey ' + rows[i].NAME + ', \n\nFrom our team here at Pier Solutions, we wanted to let you know that we have done a little re-branding. We have changed our name to... drum roll please! \n\nIndera Technologies!</p>'
                    
var text2 = '</body></html>'
                    
// send mail with defined transport object
                    let sendBatch = await transporter.sendMail({
                        from: "[email protected]", // sender address
                        to: rows[i].EMAIL,
                        // bcc: emails, // list of receivers
                        subject: "It's Official, we've rebranded!", // Subject line
                        html: text1 + req.body.htmlContent + text2
                    });

then when I send the email, it actually shows up in the email like this:

Hey Gianluca From our team here at Indera Technologies

it does all one line instead of new line.

how do I fix this?

1
  • If you're sending HTML email, newlines are not significant; they're basically the same as spaces.
    – Pointy
    May 17, 2021 at 19:49

1 Answer 1

3

If this is supposed to be part of HTML, use the <br> tag instead of \n. Or better yet, put the lower text in a separate <p> tag

Also, you might want to learn about Template Literals, it's going to make writing strings like that much easier

1
  • nice answer, I appreciate it. Totally forgot that I was writing HTML inside the js variable, it slipped my mind. Thank you!
    – Gianluca
    May 18, 2021 at 12:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.