title: Nodemailer - How to handle enetunreach error
body: <p>I have a <code>nodejs</code> application which uses the <code>nodemailer</code> plugin to send out emails. This works 99.99% of the time but yesterday the application hung up with following error in the <code>PM2</code> logs.</p>
  
  <pre><code>mod.mailer: Error: connect ENETUNREACH 2a00:1450:400c:c04::6c:465 - Local (:::0)
  </code></pre>
  
  <p>I did't find a lot of information about this kind of error. It is entirely possible that there might have been a blip in the network connection. Below is the code for the module I wrote to transport emails. How would I catch this kind of error and ensure that the application doesn't hang up but rather retries to send the email.</p>
  
  <pre><code>var nodemailer = require('nodemailer');
  var transporter = nodemailer.createTransport(process.env.TRANSPORT);
  
  function mail(options) {
      transporter.sendMail({
          from: process.env.SUBDIRECTORY + '\@' + process.env.HOST + '\ \&lt;geolytix@gmail.com\&gt;',
          to: options.to,
          subject: options.subject,
          text: options.text
      }, function (err, info) {
          if (err) {
              console.log('mod.mailer: ' + err);
          }
          console.log('mod.mailer: ' + info.response);
      });
  }
  
  module.exports = {
      mail: mail
  };
  </code></pre>