title: node.js : how to see HTML body of email using imap-simple and mailparser
body: <p>I'm trying to retrieve the HTML content of an email.
  i'm using <strong>imap-simple</strong> and <strong>mailparser</strong>.</p>
  
  <p><code>emails</code> parameter have an actual mail and i'm able to explore it's parts.</p>
  
  <p>The problem is that mailparser is not calling the events 'data' or 'headers'</p>
  
  <p>My question is how to use mailparser (or simpleparser) with imap-simple in order to see HTML content of email's body.</p>
  
  <p>This is what i run:</p>
  
  <pre><code>const imap = require('imap-simple');
  imap.connect(emailData).then(function (connection) {
      return connection.openBox('INBOX').then(function () {
          let searchCriteria = [
              'UNSEEN'
          ];
  
          let fetchOptions = {
              // TEXT - includes body of email
              // HEADER - includes subject and other headers
              bodies: ['HEADER', 'TEXT'],
              markSeen: false
          };
  
          return connection.search(searchCriteria, fetchOptions).then(function (emails) {
                  mailparser.on("data", function (mail_object) {
                      console.log(mail_object.textAsHtml);
                  });
  
                  mailparser.on("headers", function (mail_object) {
                  });
                  // send the email source to the parser
                  mailparser.write(emails[0]);
                  mailparser.end();
  </code></pre>
  
  <p>What am i doing wrong?
  Thx</p>