0

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"
    auth:
      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()

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

Comments

1

You can't add Javascript to an HTML email. Neither should you be able to do so. That would be a huge security issue.

The best approach would probably be to send out a basic HTML email with a link to a webpage that does what you want the email to do.

2 Comments

I don't really need to add javascript to the email, just send an email looking like the page as if it was rendered with javascript. Giving people access to the webpage is not an option as this requires reworking the entire login system as well as the page in question
This answer does not address a way to convert an angular / javascript based into a no-js inline-css format that works in emails

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.