title: Send Gmail SMTP email on Cloud Foundry Node.js?
body: <p>I have this code below which works local but when I deploy to <code>api.cloudfoundry.com</code>, there is no email sent at all. Can you help me to understand why? Is it because Cloud Foundry prevent some port?</p>
  
  <pre><code>var port = (process.env.VMC_APP_PORT || 3000),
      host = (process.env.VCAP_APP_HOST || 'localhost'),
      http = require('http'),
      async = require('async');
  var email   = require("emailjs");
  var server  = email.server.connect({
     user:    "username", 
     password:"password", 
     host:    "smtp.gmail.com", 
     ssl:     true
  });
  // send the message and get a callback with an error or details of the message that was sent
  http.createServer(function(req, res) {
  async.series([
     function(callback){
  server.send({
    text:    "This should be &lt;b&gt;BOLD&lt;/b&gt;...", 
    from:    "XXX &lt;xxx@gmail.com&gt;", 
    to:      "YYY &lt;yyy@gmail.com&gt;, ZZZ &lt;zzz@gmail.com&gt;",
    cc:      "",
    subject: "emailjs: test HTML body 3",
     attachment: 
     [
        {data:"&lt;h1&gt;Big a$$ title&lt;/h1&gt;&lt;br/&gt;Or maybe this should be &lt;b&gt;BOLD&lt;/b&gt; instead!!", alternative:true}
  
     ]
  }, function(err, message) { console.log(err || message); });
         callback(null, 'success');
     }
  ],
  function(err, results){
   res.writeHead(200, {'Content-Type': 'text/plain'});
   res.write(results + '...');
  });
  }).listen(port, host);
  </code></pre>
  
  <p><strong>UPDATE 1:</strong></p>
  
  <p>Look like this is a gmail SMTP issue. I did <code>vmc files myapp logs/stdout.log</code> and it showed:</p>
  
  <blockquote>
    <p>{ [Error: authorization.failed]   code: 3,   previous:    { [Error:
    bad response on command 'cGludGVyZXN0']
         code: 2,
         smtp: '535-5.7.1 Please log in with your web browser and then try again. Le arn more at\n535 5.7.1
    <a href="https://support.google.com/mail/bin/answer.py?answer=7875" rel="nofollow">https://support.google.com/mail/bin/answer.py?answer=7875</a> 4
    hn9sm22202393qab.8 - gsmtp\r\n' },   smtp: undefined }</p>
  </blockquote>
  
  <p>I tested the other SMTP or different gmail account and it works. So it is specific to this gmail account I am testing. </p>
  
  <p>I then followed this link <a href="https://support.google.com/mail/bin/answer.py?hl=en&amp;answer=78754" rel="nofollow">https://support.google.com/mail/bin/answer.py?hl=en&amp;answer=78754</a> to authorize the app </p>
  
  <blockquote>
    <p>Next step </p>
    
    <p>Sign in using the application you want to authorize access to your
    account within the next ten minutes. Google will remember the
    application after it signs in, and will allow it to access your
    account in the future as long as it uses the correct password.</p>
  </blockquote>
  
  <p>And try to login again but still no luck. I thought I supposed to receive an email within gmail to approve, but nothing so far :(</p>
  
  <p><strong>UPDATE 2:</strong></p>
  
  <p>I tried with another gmail account and went through the step to approve Cloud Foundry for app access and it works. Apparently, for the account that didn't work, I missed the "10min window" to sign in and approve Cloud Foundry. Gmail never came back and asked to have it approved again. Miss is miss :(</p>