如果新邮件通过IMAP到达node.js,则会收到通知

时间:2014-01-08 13:04:30

标签: node.js email events imap

我想在node.js中创建一个模块,它会通知我(带有事件)新邮件是否到达(使用IMAP)。到目前为止,我已经使用过IMAP模块示例代码,但任何人都可以帮助我进行下一步吗?非常感谢。

var Imap = require('imap'),
    inspect = require('util').inspect;

var imap = new Imap({
  user: 'mygmailname@gmail.com',
  password: 'mygmailpassword',
  host: 'imap.gmail.com',
  port: 993,
  tls: true,
  tlsOptions: { rejectUnauthorized: false }
});

function openInbox(cb) {
  imap.openBox('INBOX', true, cb);
}

imap.once('ready', function() {
  openInbox(function(err, box) {
    if (err) throw err;

/* ??? */


 });

});


imap.once('error', function(err) {
  console.log(err);
});

imap.once('end', function() {
  console.log('Connection ended');
});

imap.connect();

1 个答案:

答案 0 :(得分:0)

阅读RFC 3501。如果不了解IMAP协议,就绝对不可能使用某个IMAP库来实现使用IMAP的客户端。

或者,寻找一些从您那里抽象出IMAP协议的高级库,并提供一些自己的统一API。