Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

External HTML file with CSS as email content in nodemailer

Does anyone know how to tell Node.js´ module nodemailer to use an external HTML file (with links to stylesheets) as email content?

I am able to type in HTML tags as email content but I prefer loading complete HTML files. I´m using nodemailer 1.3.0.

Unfortunately I can´t find any example covering this issue for the actual nodemailer version.

Ideas?

like image 786
wurstbrotrest Avatar asked Sep 23 '14 22:09

wurstbrotrest


People also ask

How do I send an HTML email with Nodemailer?

In server. js , add the following code, which will trigger sending an email: const hbs = require('nodemailer-express-handlebars') const nodemailer = require('nodemailer') const path = require('path') // initialize nodemailer var transporter = nodemailer.

How do I send an email with Nodemailer?

In short, what you need to do to send messages, would be the following: Create a Nodemailer transporter using either SMTP or some other transport mechanism. Set up message options (who sends what to whom) Deliver the message object using the sendMail() method of your previously created transporter.


1 Answers

You should use inline css, not a separate file since HTML rendering of head elements and such are defined by provider not by nodemailer.

I'd recomend mailChim's css inliner tool, it's pretty handy, just set the

html: '<div style="font - family: verdana; max-width:500px; margin-left">' + 'more string and string'
like image 170
Gabriel Balsa Avatar answered Sep 27 '22 18:09

Gabriel Balsa