title: Send email with Angular and NodeMailer
body: <p>how is it going?</p>
  
  <p>I am trying to figure out how to send an email with Angular 5 and Node.js -using nodemailer-.</p>
  
  <p>What I want to archive is when some user make an appointment in the page and system gets the provided email and send some information to the user when they click the button "Schedule my ....."</p>
  
  <p>As you'll see in <em>appointment.component.ts</em>, when the user click the button a variable change to "true" to display some hidden div to the user and displays as well a snackbar but nothing happens. No error in the console log nor anything. Any ideas?</p>
  
  <p>Here is my code below. Thanks in advance.</p>
  
  <p><strong>server.js</strong></p>
  
  <pre><code>const express    = require('express');
  const path       = require('path');
  const http       = require('http');
  const bodyParser = require('body-parser');
  const nodeMailer = require('nodemailer');
  
  const api = require('./server/routes/api');
  
  const app = express();
  
  app.use(bodyParser.json());
  app.use(bodyParser.urlencoded({ extended: true }));
  app.use(express.static(path.join(__dirname, 'dist')));
  
  app.use('/api', api);
  app.get('*', (req, res) =&gt; {
    res.sendFile(path.join(__dirname, 'dist/index.html'));
  });
  app.post('/sendemail', (req, res) =&gt; {
    let transporter = nodeMailer.createTransport({
      host: 'smtp.gmail.com',
      port: 465,
      secure: true,
      auth: {
        user: 'xxxxx@gmail.com',
        pass: 'xxxxxxxxxxxxx'
      }
    });
    let mailOptions = {
      from: '"Nourish Team" &lt;no-reply@nourish.io&gt;',
      to: "anyemailhere@gmail.com",
      subject: 'Test',
      text: 'Hello!',
      html: '&lt;b&gt;Testing email function&lt;/b&gt;'
    };
  
    transporter.sendMail(mailOptions, (error, info) =&gt; {
      if(error) {
        return console.log(error);
      }
      console.log('Message sent');
    })
  });
  
  const port = process.env.PORT || '3000';
  app.set('port', port);
  
  const server = http.createServer(app);
  server.listen(port, () =&gt; console.log(`API running on localhost:${port}`));
  </code></pre>
  
  <p><strong>appointment.component.html</strong></p>
  
  <pre><code>&lt;form novalidate action="/send-email" method="POST" (ngSubmit)="sendEmail()"&gt;
        &lt;mat-form-field class="middle-width" ngClass.xs="full-width"&gt;
          &lt;input matInput placeholder="Nombre Completo" [formControl]="fullName" required&gt;
          &lt;mat-error *ngIf="fullName.hasError('pattern') &amp;&amp; !fullName.hasError('required')"&gt;
            El campo solo acepta letras.
          &lt;/mat-error&gt;
          &lt;mat-error *ngIf="fullName.hasError('required')"&gt;
            ¡Este cambo es &lt;strong&gt;requerido&lt;/strong&gt;!
          &lt;/mat-error&gt;
        &lt;/mat-form-field&gt;
        &lt;mat-form-field class="middle-width" ngClass.xs="full-width"&gt;
          &lt;input matInput placeholder="Correo Electrónico" type="email" [formControl]="cEmail" required&gt;
          &lt;mat-error *ngIf="cEmail.hasError('email') &amp;&amp; !cEmail.hasError('required')"&gt;
            Debes introducir un correo electrónico válido
          &lt;/mat-error&gt;
          &lt;mat-error *ngIf="cEmail.hasError('required')"&gt;
            ¡Este cambo es &lt;strong&gt;requerido&lt;/strong&gt;!
          &lt;/mat-error&gt;
        &lt;/mat-form-field&gt;
        &lt;mat-form-field class="middle-width" ngClass.xs="full-width"&gt;
          &lt;input matInput placeholder="Teléfono" type="tel" [formControl]="phone" maxlength="14" mask="(000) 000 0000" required&gt;
          &lt;mat-hint align="end"&gt;{{phone.value.length}} / 10&lt;/mat-hint&gt;
          &lt;mat-error *ngIf="phone.hasError('pattern') &amp;&amp; !phone.hasError('required')"&gt;
            El campo sólo acepta números
          &lt;/mat-error&gt;
          &lt;mat-error *ngIf="phone.hasError('required')"&gt;
            ¡Este cambo es &lt;strong&gt;requerido&lt;/strong&gt;!
          &lt;/mat-error&gt;
        &lt;/mat-form-field&gt;
        &lt;mat-form-field class="middle-width" ngClass.xs="full-width"&gt;
          &lt;input matInput [matDatepicker]="picker" placeholder="Elegir fecha"&gt;
          &lt;mat-datepicker-toggle matSuffix [for]="picker"&gt;&lt;/mat-datepicker-toggle&gt;
          &lt;mat-datepicker touchUi="true" #picker&gt;&lt;/mat-datepicker&gt;
        &lt;/mat-form-field&gt;
        &lt;br&gt;
        &lt;button mat-raised-button type="submit"&gt;Schedule My Appointment&lt;/button&gt;
      &lt;/form&gt;
  </code></pre>
  
  <p><strong>appointment.component.ts</strong></p>
  
  <pre><code>sendEmail() {
    this.sucess = true;
    this.snackBar.open('Información enviada exitosamente.', 'x', {
      duration: 5000,
    });
    this.name = this.fullName.value;  
      this.http.post('/sendemail', this.cEmail).subscribe(data =&gt; {
      console.log(data);
    });
  }
  </code></pre>
  
  <blockquote>
    <p>I assume this code is to concatenated the node.js code into Angular5 app: <strong>this.http.post('/sendemail', this.cEmail).subscribe(data => {console.log(data);});</strong></p>
  </blockquote>