Monday, 17 April 2017

how give notification from nodejs in angular

i have used mailgun in nodejs to send mail.I am able to send mail but want to acknowledge the user about the mail send or not. how can i do it from server.js file

app.post( "/home", function( req, res ) {
    var api_key = 'key-7a2322746b659a0a26d66f0c07e27db1';
    var domain = 'sandbox7102872c028b4e199dcaafbbac291c22.mailgun.org';
    var mailgun = require( 'mailgun-js' )( {
      apiKey: api_key,
      domain: domain
    } );
    var data = {
      from: 'Gundeep <postmaster@sandbox7102872c028b4e199dcaafbbac291c22.mailgun.org>',
      to: 'gundeeps2786@gmail.com',
      subject: req.body.name,
      html: '<b>Client Email Address: </b>' + req.body.email + '<br><b>Subject</b><br>' + req.body.subject +
        '<br><b>Message</b><br>' + req.body.message
    };
    mailgun.messages().send( data, function( error, body ) {
      console.log( body );
      //var element = document.getElementById("mailSent"); element.innerHTML = "New text!";
      if ( !error ) {
         res.sendFile( path.join( __dirname, 'index.html' ) );
         // alert('hello');
       }
      // res.send( contact.tpl ); 
      else res.send( "Mail not Send" );
    } );
  } )



via gundeep

No comments:

Post a Comment