Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

imap

Package Overview
Dependencies
Maintainers
1
Versions
54
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

imap

An IMAP module for node.js that makes communicating with IMAP servers easy

  • 0.8.19
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
170K
decreased by-12.22%
Maintainers
1
Weekly downloads
 
Created

What is imap?

The 'imap' npm package is a client library for accessing email accounts via the Internet Message Access Protocol (IMAP). It allows you to connect to an IMAP server, authenticate, and perform various operations such as fetching emails, searching for messages, and managing mailboxes.

What are imap's main functionalities?

Connecting to an IMAP server

This code demonstrates how to establish a connection to an IMAP server using the 'imap' package. You need to provide your email credentials and server details.

const Imap = require('imap');
const imap = new Imap({
  user: 'your-email@example.com',
  password: 'your-password',
  host: 'imap.example.com',
  port: 993,
  tls: true
});
imap.connect();

Fetching emails

This code demonstrates how to fetch the headers of the first 10 emails in the INBOX. It opens the INBOX, fetches the specified range of emails, and logs the headers to the console.

imap.once('ready', function() {
  imap.openBox('INBOX', true, function(err, box) {
    if (err) throw err;
    const f = imap.seq.fetch('1:10', {
      bodies: 'HEADER.FIELDS (FROM TO SUBJECT DATE)',
      struct: true
    });
    f.on('message', function(msg, seqno) {
      msg.on('body', function(stream, info) {
        let buffer = '';
        stream.on('data', function(chunk) {
          buffer += chunk.toString('utf8');
        });
        stream.once('end', function() {
          console.log('Parsed header: %s', buffer);
        });
      });
    });
    f.once('error', function(err) {
      console.log('Fetch error: ' + err);
    });
    f.once('end', function() {
      console.log('Done fetching all messages!');
      imap.end();
    });
  });
});

Searching for emails

This code demonstrates how to search for unseen emails since a specific date. It opens the INBOX, performs the search, and fetches the results.

imap.once('ready', function() {
  imap.openBox('INBOX', true, function(err, box) {
    if (err) throw err;
    imap.search(['UNSEEN', ['SINCE', 'May 20, 2020']], function(err, results) {
      if (err) throw err;
      const f = imap.fetch(results, { bodies: '' });
      f.on('message', function(msg, seqno) {
        console.log('Message #%d', seqno);
        msg.on('body', function(stream, info) {
          let buffer = '';
          stream.on('data', function(chunk) {
            buffer += chunk.toString('utf8');
          });
          stream.once('end', function() {
            console.log('Parsed message: %s', buffer);
          });
        });
      });
      f.once('error', function(err) {
        console.log('Fetch error: ' + err);
      });
      f.once('end', function() {
        console.log('Done fetching all messages!');
        imap.end();
      });
    });
  });
});

Other packages similar to imap

Keywords

FAQs

Package last updated on 06 Dec 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc