title: POST request error - TypeError: Cannot read property 'name' of undefined
body: <p>I am having some trouble using nodemailer to send email. I am sure I have it all set up correctly. Bumped into some posts about depreciated code with the body parser, I tried their solutions...I think I did that right also. </p>
  
  <p>p.s a bit of a node noob here.</p>
  
  <p>Node version: 4.4.5
  Express version: 4.13.4
  Nodemailer version: 2.4.2</p>
  
  <p>app.js</p>
  
  <pre><code>/*Application file */
  'use strict';
  
  var express = require('express');
  var app = express(); //create the Application
  var pug = require('pug'); //require pug for templates
  var nodemailer = require('nodemailer');
  var bodyParser = require('body-parser');
  
  app.use(bodyParser.urlencoded({ extended: true }));
  app.use(bodyParser.json());
  
  //require modules
  var blog = require('./routes/blog');
  var pages = require('./routes/pages');
  var tutorials = require('./routes/tutorials');
  var home = require('./routes/home');
  var contact = require('./routes/contact');
  var port = 4000;
  
  app.set('view-engine', 'pug');
  app.set('views', __dirname + '/templates');
  
   //ROUTES//
  app.use('/static', express.static(__dirname + '/public'));
  app.use('/', home);
  app.use('/pages', pages);
  app.use('/blog', blog);
  app.use('/tutorials', tutorials);
  app.use('/', contact);
  
   //SERVERS//
  //listern on port
  app.listen(port, function () {
      setInterval(function () {
          console.log('server is running on port: ' + port);
      },10000)
  });
  </code></pre>
  
  <p>contact.js</p>
  
  <pre><code>var express = require('express');
  var router = express.Router();
  var nodemailer = require("nodemailer");
  
  router.get('/contact', function (req, res) {
      var path = req.path;
      res.locals.path = path;
      res.render('contact.pug');
  });
  
  router.post('/contact/send', function (res, req) {
      var transporter = nodemailer.createTransport({
          service: 'Gmail',
          auth: {
              user: 'myemail@gmail.com',
              pass: 'pass'
          }
      });
  
      var conName = req.body.name;
      var conEmail = req.body.email;
      var conTopic = req.body.topic;
      var conMessage = req.body.message;
      var text = 'New Mail. Name: ' + conName + ' Email: ' + conEmail + ' Topic: ' + conTopic+ ' Message: ' + conMessage;
      var html = '&lt;p&gt;New Mail.&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Name: ' + conName + '&lt;/li&gt;&lt;li&gt;Email: ' + conEmail + '&lt;/li&gt;&lt;li&gt;Topic: ' + conTopic + '&lt;/li&gt;&lt;li&gt;Message: ' + conMessage + '&lt;/li&gt;&lt;/ul&gt;';
  
      var mailOptions = {
          from: 'No one &lt;noone@email.com',
          to: 'myemail@gmail.com',
          subject: 'Website Submission',
          text: text,
          html: html
      };
  
      transporter.sendMail(mailOptions, function (error, info) {
          if(error){
              console.log(error);
              res.redirect('/');
          } else {
              console.log('Message sent: ' + info.response);
              res.redirect('/');
          }
      });
  });
  
  module.exports = router;
  </code></pre>
  
  <p>contact.pug</p>
  
  <pre><code>extends ./home-layout.pug
  block content
      div.section
          div.container
              div.row.content-container
                  div.col.s12.center.heading
                      h4 Contact
                      br
                  div.row
                    form(method="post", action="contact/send").col.s12
                      div.row
                          div.input-field.col.s6.form-padding
                              input.validate(name="name", type='text')
                          div.input-field.col.s6.form-padding
                              input#last_name.validate(placeholder='Email', name="email", type='email')
                      div.row
                        div.input-field.col.s6.form-padding
                          input#input_text(placeholder='Topic',type='text', name="topic", length='10')
                      div.row
                        div.input-field.col.s12.form-padding
                          textarea#textarea1.materialize-textarea(placeholder='Message', name="message", length='120')
                      a
                          button(type="submit").waves-effect.waves-light.btn Send
  </code></pre>