Sending a webpage that uses angular as an email

Sending a webpage that uses angular as an email


I have a webpage (using angular and some javascript) that requests data from a server and displays as a table.

I would like to send a copy of this webpage by email, (using node and nodemailer).

I use a http.get to get the html of the webpage, however naturally this only gets me the HTML. I would like to get the page as shown in the browser (after loading has completed) into the email.

How would I accomplish this?

This is my own attempt that naturally only works with a pure html page, and so lacks the javascript and the angular stuff. Please note that this uses coffeescript.

nodemailer = require("nodemailer")
http = require 'http'

sendmail = (html)->
  transport = nodemailer.createTransport("SMTP",{
    service: "Gmail"
      user: u
      pass: p

  mailOptions =
    from: f
    to: t
    subject: s
    html: html

  transport.sendMail mailOptions, (err,res)->
    console.log err if err?
    do transport.close

http.get 'http://localhost:3000/something', (res) ->
  res.on 'data', (data) ->
    sendmail data.toString()
Problem courtesy of: user2005152


PhantomJS is likely the solution you’re looking for. It’s a headless Webkit browser that will render your pages on the server to a form that could be mailed. The main application of this is enabling SEO for Single Page Applications (SPAs). Lots more info here: “Single-page” JS websites and SEO

Solution courtesy of: dankohn


Leave a Reply

Your email address will not be published. Required fields are marked *