title: How to send Email using Angular 4 and Node Js using nodemailer package
body: <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>&lt;!-- Server.js file of Node JS--&gt;
  
  var http = require('http');
  var nodemailer = require('nodemailer');
  var bodyParser = require('body-parser');
  
  var connect = require('connect');
  
  var app = connect();
  app.use( bodyParser.json() );       // to support JSON-encoded bodies
  app.use(bodyParser.urlencoded({     // to support URL-encoded bodies
   extended: true
  }));
  sendemail = function(request, response, next){
   var transporter = nodemailer.createTransport({
    service: 'gmail',
      auth: {
        user: 'senderid@gmail.com',
        pass: 'senderpassword',
        host: 'smtp.gmail.com', 
        ssl: true
      }
   });
   var mailOptions = {
     from: 'senderid@gmail.com',
     to: request.body.emailid, //get from form input field of html file
     subject: 'Sending Email using Node.js',
     text: 'That was easy!'
   }; 
    transporter.sendMail(mailOptions, function(error, info){
      if (error) {
        alert(error);
      } else {
        alert('Email sent: ' + info.response);
      }
    });
    next();
  };
  app.use("/sendemail", sendemail);
  http.createServer(app).listen(8888);
  console.log("Server is listening......!!");
  
  
      &lt;!-- userservice.ts file --&gt;
  
      import { Injectable } from '@angular/core';
      import { Http, Headers } from '@angular/http';
  
      @Injectable()
      export class UserService {
  
        constructor(private http: Http) { }
  
        addNew(usercreds) {
          const emailid = 'email=' + usercreds.email;            
          this.http.post('http://localhost:8888/sendemail', emailid).subscribe((data) =&gt; {
              if (data.json().sucess) {
                console.log('mail sent');
                }
           });
        }
  
      }
      &lt;!-- This is app.component.ts file--&gt;
          import { Component } from '@angular/core';
          import { UserService } from './user.service';
  
          @Component({
            selector: 'app-root',
            templateUrl: './app.component.html',
            styleUrls: ['./app.component.css']
          })
          export class AppComponent {
            title = 'app';
            newUser = {
              email: '',
              password: ''
            };
            constructor (private user: UserService) {}
            addUser() {
              this.user.addNew(this.newUser);
            }
          }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>    &lt;form (ngSubmit)="addUser()"&gt; 
            &lt;md-card-content&gt;
             &lt;div&gt;
              &lt;md-icon&gt;email&lt;/md-icon&gt;
              &lt;md-input-container&gt;
               &lt;input mdInput type="email" placeholder="Enter Email" name="email" [(ngModel)]="newUser.email"&gt;
              &lt;/md-input-container&gt;
             &lt;/div&gt;
             &lt;div&gt;
              &lt;md-icon&gt;lock&lt;/md-icon&gt;
              &lt;md-input-container&gt;
               &lt;input mdInput type="password" placeholder="Enter Password" name="password" [(ngModel)]="newUser.password"&gt;
              &lt;/md-input-container&gt;  
             &lt;/div&gt;
            &lt;/md-card-content&gt;
            &lt;md-card-actions&gt;
             &lt;button md-raised-button color="primary" type="submit"&gt;Send Email&lt;/button&gt;
            &lt;/md-card-actions&gt;
           &lt;/form&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>I have a html component in Angular 4 in their i have form which carry 2 fields one is email and other is password. I am using only email of input field for sending email to client id.</p>
  
  <p>For that i have a user service in that i am sending the data using http post method to my Node JS file.</p>
  
  <p>Now I want to email form user and get it into my server.js file so when user register the email sent their email id which he put into input filed of form.</p>