Search This Blog

Thursday, October 13, 2016

Nodejs nodemailer - Send Email

1. go to cmd prompt in your root project folder 
   Type npm install nodemailer


2. create mail.js

var express = require('express');
var nodemailer = require("nodemailer");
var smtpTransport = require("nodemailer-smtp-transport")
var app = express();

var smtpTransport = nodemailer.createTransport(smtpTransport({
    host : "smpt.gmail.com",
    secureConnection : false,
    port: 587,
    auth : {
        user : "drvijayy2k2@gmail.com",
        pass : "test123"    }
}));
app.get('/send',function(req,res){
    var mailOptions={
        from : "drvijayy2k2@gmail.com",
        to : "drvijayy2k2@gmail.com",
        subject : "Your Subject",
        text : "Your Text",
        html : "HTML GENERATED",
        /*attachments : [
            {   // file on disk as an attachment                //filename: 'a.txt',                path: 'd:/a.txt' // stream this file, use only path property and send the file name in the end, else you may get folder read error            }
        ]*/
    }
    console.log(mailOptions);
    smtpTransport.sendMail(mailOptions, function(error, response){
        if(error){
            console.log(error);
            res.end("error");
        }else{
            console.log(response.response.toString());
            console.log("Message sent: " + response.message);
            res.end("sent");
        }
    });
});

app.listen(3000,function(){
    console.log("Express Started on Port 3000");
});



3. Go to command prompt where the mail.js stored
    Type node mail.js



4. open brower
 http://localhost:3000/send



Wednesday, October 12, 2016

NodeJs VelocityJs in web app - Template Engine

just create a sample  velocity-text.js  file.

/** * Created by drvijay on 12-10-2016. */
   var context = {
        "name": "velocity"    }

var initialString = "Hello, ${name}!";

var velocityjs = require("velocityjs");
var renderedString = velocityjs.render(initialString,context);
console.log(context);
console.log(initialString);
console.log(renderedString);


// go to cmd type node velocity-text.js



INSTALL

First install velocityjs in your node_modules

npm install velocityjs

Now from your project (where the node_modules mentioned above exists) use browserify

browserify -r velocityjs  > velocity.js

This will create a velocity.js file that you can include in your website directly. If you don't have browserify then do npm install -g browserify

Usage

In your webpage js file first require velocityjs

var velocityjs = require("velocityjs");

Now to get the templated html do

var renderedString = velocityjs.render(initialString,context)

Note that velocity does not care if your initial string was html or not, you need to ensure that

NodeJs VelocityJs in web app - Template Engine

just create a sample  velocity-text.js  file.

/** * Created by drvijay on 12-10-2016. */
   var context = {
        "name": "velocity"    }

var initialString = "Hello, ${name}!";

var velocityjs = require("velocityjs");
var renderedString = velocityjs.render(initialString,context);
console.log(context);
console.log(initialString);
console.log(renderedString);


// go to cmd type node velocity-text.js



INSTALL

First install velocityjs in your node_modules

npm install velocityjs

Now from your project (where the node_modules mentioned above exists) use browserify

browserify -r velocityjs  > velocity.js

This will create a velocity.js file that you can include in your website directly. If you don't have browserify then do npm install -g browserify

Usage

In your webpage js file first require velocityjs

var velocityjs = require("velocityjs");

Now to get the templated html do

var renderedString = velocityjs.render(initialString,context)

Note that velocity does not care if your initial string was html or not, you need to ensure that

Hit Counter


View My Stats