title: Using mail-listener2 to read emails from Hoodiecrow
body: <p>I use <strong>Hoodiecrow</strong> (<a href="http://hoodiecrow.com/" rel="nofollow">http://hoodiecrow.com/</a>) as an IMAP server and <strong>mail-listener2</strong> (<a href="https://www.npmjs.com/package/mail-listener2" rel="nofollow">https://www.npmjs.com/package/mail-listener2</a>) as a IMAP client. Both are npm modules.</p>
  
  <p>I am trying to retrieve messages from Hoodiecrow using the mail-listener2 client.</p>
  
  <p>Here is my mail-listener2 configuration:</p>
  
  <pre><code>var MailListener = require('mail-listener2');
  
  // here goes your email connection configuration
  var mailListener = new MailListener({
      username: 'testuser',
      password: 'testpass',
      host: 'localhost',
      port: 1143, // imap port
      tls: false,
      tlsOptions: {rejectUnauthorized: true},
      mailbox: 'INBOX', // mailbox to monitor
      searchFilter: ['UNSEEN'], // the search filter being used after an IDLE notification has been retrieved
      markSeen: true, // all fetched email willbe marked as seen and not fetched next time
      fetchUnreadOnStart: true, // use it only if you want to get all unread email on lib start. Default is `false`,
      mailParserOptions: {streamAttachments: true}, // options to be passed to mailParser lib.
      attachments: true, // download attachments as they are encountered to the project directory
      attachmentOptions: {directory: 'attachments/'} // specify a download directory for attachments
  });
  
  mailListener.start();
  
  mailListener.on("server:connected", function () {
      console.log("Mail listener initialized");
  });
  
  
  
  var getLastEmail = function () {
      var deferred = protractor.promise.defer();
      console.log("Waiting for an email...");
  
      mailListener.on("mail", function (mail) {
          deferred.fulfill(mail);
      });
      return deferred.promise;
  };
  
  global.mailListener = mailListener;
  global.getLastEmail = getLastEmail;
  </code></pre>
  
  <p>However, I am not sure how to configure my application to use the Hoodiecrow IMAP server.</p>
  
  <p>Can someone please help?</p>