title: How to send email from form using Nodemailer
body: <p>Let's start off by saying I am a beginner at node and javascript. I have a website that I built using HTML, CSS, and ASP.NET. There is an email form setup on my website that i wanted to convert from ASP.NET to Node.js simply for the learning experience. I have followed several different tutorials to attempting to get this piece to work. I keep coming up short! </p>
  
  <p>I have successfully made my html email form accept data and the node picks it up. However attempting to grab the node and send it in the form of an email using nodemailer, not so much. I notice several tutorials use "routes" I would like to avoid this option because it simply goes over my head. If someone could explain how to do that or why not to do that or how it cant be done? I would be appreciative. Here's my code that i have so far: </p>
  
  <p>Javascript/Node: </p>
  
  <pre><code>var nodemailer = require('nodemailer');
  var bodyParser = require('body-parser');
  var express = require('express');
  var app = express();
  
  app.use(bodyParser.urlencoded({
      extended: true
  }));
  
  app.post('/contact', function(req, res) {
      var mailOpts, smtpConfig;
      //Setup Nodemailer transport, I chose gmail. Create an application-specific             password to avoid problems.
      smtpConfig = nodemailer.createTransport('SMTP', {
          service: 'Gmail',
          auth: {
              user: "&lt;myUser&gt;",
              pass: "&lt;myPassword&gt;"
          }
      });
      //Mail options
      mailOpts = {
          from: req.query.name + ' &amp;lt;' + req.query.email + '&amp;gt;',
          //grab form    data from the request body object
          to: '&lt;other user&gt;',
          subject: 'Website contact form',
          text: req.query.message
      };
      smtpConfig.sendMail(mailOpts, function(error, response) {
          //Email not sent
          if (error) {
              res.end("Email send failed");
              //res.render('contact', { title: 'Raging Flame Laboratory - Contact',   msg: 'Error occured, message not sent.', err: true, page: 'contact' })
              //console.log("error");
          }//Yay!! Email sent
          else {
              res.end("Email send successfully");
              //res.render('contact', { title: 'Raging Flame Laboratory - Contact',  msg: 'Message sent! Thank you.', err: false, page: 'contact' })
              //console.log("success");
          }
      });
  });
  
  app.listen(8081, function() {
      console.log('Server running at http://127.0.0.1:8081/');
  });
  </code></pre>
  
  <p>HTML: </p>
  
  <pre><code>&lt;form action="http://127.0.0.1:8087/contact" method="post"&gt;
      &lt;b&gt;send us a quote&lt;/b&gt;
      &lt;/br&gt;
      &lt;input type="text" name="name" id="name" value="Name"&gt;
      &lt;/br&gt;
      &lt;!--input type="text" name="bname" id="bname" value="Business Name"&gt;&lt;/br&gt;--&gt;
      &lt;input type="text" name="email" id="email" value="Email Address"&gt;
      &lt;/br&gt;
      &lt;textarea name="message" id="message" cols="30" rows="10"&gt;Enter detailed information here&lt;/textarea&gt;
      &lt;/br&gt;
      &lt;input type="submit" name="Submit" id="Submit" value="send message"&gt;
  &lt;/form&gt;
  </code></pre>