title: Handle timeout in NodeMailer
body: <p>I am using <a href="https://github.com/nodemailer/nodemailer" rel="nofollow noreferrer">nodemailer</a> (v1.0.4) to send emails in my Node application. Here is the code:</p>
  
  <p><strong>smtpUtil.js</strong></p>
  
  <pre><code>var nodemailer = require("nodemailer");
  var config = require("../config").mailgun;
  
  var transporter = nodemailer.createTransport({
    service: 'Mailgun',
    auth: {
      user: config.username,
      pass: config.password
    },
  });
  
  transporter.mailSent = function(mailOptions, callback) {
    transporter.sendMail(mailOptions, function(error, response) {
      if (error) {
        console.log("Error in sending mail", error);
        callback(new Error(error));
      } else {
        console.log("Email sent successfully");
        callback();
      }
    });
  }
  
  module.exports = transporter;
  </code></pre>
  
  <p>I just include this <code>smtpUtil.js</code> in other files and then call <code>transporter.mailSent(mailOpts, callbackFn);</code> to send the email.</p>
  
  <p><strong>My question is: how to add max timeout time &amp; gracefully handle those in the process?</strong></p>
  
  <p>The reason I am asking about above configuration is that recently in code, I invoked <code>transporter.mailSent(mailOpts, callbackFn)</code>. But due to some reason (possibly infinite timeout), the <code>callbackFn</code> was never triggered (neither success nor failure).</p>
  
  <p>Latest <a href="https://community.nodemailer.com/2-0-0-beta/setup-smtp/" rel="nofollow noreferrer">NodeMailer module</a> though gives 3 timeout options, as follows:</p>
  
  <ul>
  <li><strong>options.connectionTimeout</strong> how many milliseconds to wait for the
  connection to establish</li>
  <li><strong>options.greetingTimeout</strong> how many milliseconds to wait for the greeting after connection is established</li>
  <li><strong>options.socketTimeout</strong> how many milliseconds of inactivity to allow</li>
  </ul>
  
  <p>But I am not sure which one would be relevant here to tackle the <code>callbackFn</code> never getting triggered issue.</p>