我正在使用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