title: Simple email sender with NodeJS and Express
body: <p>I'm totally new to web development and working with web related concepts and frameworks (IPs, networks, routers, I cringe everytime :D ).</p>
  
  <p>But, thanks to some internship work I have "forced myself" to work with this and thanks to lots of digging on the internet I have managed to develop a super simple app that can send emails if I am under my localhost. But, I have some (many) questions, but first, the files that comprise all of my code:</p>
  
  <p>Package.json file</p>
  
  <pre class="lang-json prettyprint-override"><code>{
      "name": "email-node",
      "version": "1.0.0",
      "dependencies": {
          "nodemailer": "~0.7.1",
          "express": "~4.5.1"
      }
  }
  </code></pre>
  
  <p>Index.html</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;html&gt;
  &lt;head&gt;
      &lt;title&gt;Node.JS Email application&lt;/title&gt;
      &lt;script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"&gt;&lt;/script&gt;
      &lt;script&gt;// &lt;![CDATA[
      $(document).ready(function(){
          var from,to,subject,text;
          $("#send_email").click(function(){     
              to=$("#to").val();
              subject=$("#subject").val();
              text=$("#content").val();
              $("#message").text("Sending E-mail...Please wait");
              $.get("http://localhost:3000/send",{to:to,subject:subject,text:text},function(data) {
                  if(data=="sent") {
                      $("#message").empty().html("Email is been sent at "+to+" . Please check inbox !");
                  }
              });
          });
      });
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;div id="container"&gt;
          &lt;h1&gt;Mailer In Node.JS&lt;/h1&gt;
          &lt;input id="to" type="text" placeholder="Enter E-mail ID where you want to send" /&gt;
          &lt;input id="subject" type="text" placeholder="Write Subject" /&gt;
          &lt;textarea id="content" cols="40" rows="5" placeholder="Write what you want to send"&gt;&lt;/textarea&gt;
          &lt;button id="send_email"&gt;Send Email&lt;/button&gt;
          &lt;span id="message"&gt;&lt;/span&gt;
      &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>app.js File</p>
  
  <pre class="lang-js prettyprint-override"><code>var express=require('express');
  var nodemailer = require("nodemailer");
  var app=express();
  /*
  Here we are configuring our SMTP Server details.
  STMP is mail server which is responsible for sending and recieving email.
  */
  var smtpTransport = nodemailer.createTransport("SMTP",{
      service: "Gmail",
      auth: {
          user: "MYGMAIL@gmail.com",
          pass: "MYGMAILPASS"
      }
  });
  /*------------------SMTP Over-----------------------------*/
  
  /*------------------Routing Started ------------------------*/
  
  app.get('/',function(req,res){
      res.sendfile('index.html');
  });
  app.get('/send',function(req,res){
      var mailOptions={
          to : req.query.to,
          subject : req.query.subject,
          text : req.query.text
      }
      console.log(mailOptions);
      smtpTransport.sendMail(mailOptions, function(error, response){
          if(error){
              console.log(error);
              res.end("error");
          }else{
              console.log("Message sent: " + response.message);
              res.end("sent");
          }
      });
  });
  
  /*--------------------Routing Over----------------------------*/
  
  app.listen(3000,function(){
      console.log("Express Started on Port 3000");
  });
  </code></pre>
  
  <p>From what I have read here is what I concluded:</p>
  
  <p>Node.js + Express applications always "listens" to incoming connections on port 3000 so that is the value I use.</p>
  
  <p>Ideally, to send stuff from a website instead of my localhost I believe that the problem lies on the index.html file.</p>
  
  <p>Specifically, this line:</p>
  
  <pre><code>$.get("http://localhost:3000/send",{to:to,subject:subject,text:text},function(data){
  </code></pre>
  
  <p>where instead of using <a href="http://localhost:3000/send" rel="nofollow">http://localhost:3000/send</a> I would use something like:</p>
  
  <p><a href="http://bruno-oliveira.github.io:3000/send" rel="nofollow">http://bruno-oliveira.github.io:3000/send</a></p>
  
  <p>I have read countless forums and posts, tried everything from:</p>
  
  <pre><code>$.get("/send",{to:to,subject:subject,text:text},function(data){
  </code></pre>
  
  <p>to searching for github servers IP adress range ( <a href="https://developer.github.com/v3/meta/" rel="nofollow">https://developer.github.com/v3/meta/</a> ) to try and use them directly there and nothing seems to work...</p>
  
  <p>The application is supposedly host here:</p>
  
  <p><a href="http://bruno-oliveira.github.io/" rel="nofollow">http://bruno-oliveira.github.io/</a></p>
  
  <p>Can someone help me?</p>
  
  <p>Best,</p>
  
  <p>Bruno</p>