Skip to content

Instantly share code, notes, and snippets.

@ArnauAregall
Created January 22, 2016 23:54
Show Gist options
  • Save ArnauAregall/be22e24d499c7c4cf916 to your computer and use it in GitHub Desktop.
Save ArnauAregall/be22e24d499c7c4cf916 to your computer and use it in GitHub Desktop.
Node 4.0.x IMAP inbox reader example
'use strict';
// npm install inbox -save
// npm install stream -save
var inbox = require('inbox'),
Stream = require('stream');
var client = inbox.createConnection(false, 'mail.bar.es', {
secureConnection: true,
auth: {
user: '[email protected]',
pass: '123'
}
})
client.on('connect', () => {
console.info('Conected to server')
client.openMailbox('INBOX', (err, info) => {
if (err) {
console.error('Error opening INBOX: %s', err);
throw err;
}
console.info('Opened INBOX: ', info);
})
})
client.on('new', (message) => {
console.info('Received message: ', message)
client.createMessageStream(message.UID).pipe((() => {
var outStream = new Stream();
outStream.writable = true;
outStream.write = (data) => {
console.info('--- Message content ----')
console.info('------------------------')
console.info(new Buffer(data).toString())
}
return outStream
})(), {end: false})
})
try {
client.connect()
} catch (e) {
console.error('Error connecting to e-mail inbox: ', e)
process.exit(0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment