尝试使用mail-listener4 Nodejs读取邮件

时间:2018-03-29 18:19:51

标签: node.js email callback imap

我正在使用npm中随库提供的示例代码 npm link

var MailListener = require("mail-listener4");

var mailListener = new MailListener({
  username: "******@gmail.com",
  password: "***********",
  host: "imap.gmail.com",
  port: 993, // imap port
  tls: true,
  connTimeout: 10000, 
  authTimeout: 5000, 
  debug: console.log, 
  tlsOptions: { rejectUnauthorized: false },
  mailbox: "INBOX", // mailbox to monitor
  searchFilter: ["ALL"], 
  markSeen: true, 
  fetchUnreadOnStart: false, 
  mailParserOptions: {streamAttachments: true}, 
  attachments: true, 
  attachmentOptions: { directory: "attachments/" } 
   });

mailListener.start(); // start listening

mailListener.on("error", function(err){
    console.log(err);
 });

这是收到邮件时调用的功能: 但我不知道它是如何运作的

   mailListener.on("mail", function(mail, seqno, attributes){
         console.log("emailParsed");
         // I know that i should get the mail body here 
         // but i don't know how 

     });



mailListener.on("attachment", function(attachment){
   console.log(attachment.path);
  });

我希望将邮件正文作为字符串或xml 这是我收到邮件后在控制台上得到的东西 secreenshoot after reciving a mail

0 个答案:

没有答案