保存附件NodeJS

时间:2018-01-15 19:47:15

标签: node.js pop3

我正在使用NodeJS库(yapople)从我的pop3服务器读取电子邮件。我遇到的问题是下载附件。不知道如何做到这一点。我找回了一个mailparser对象,在那里我看到了附件。这是我到目前为止所做的。

var fs = require('fs');
const simpleParser = require('mailparser').simpleParser;

var Client = require('yapople').Client;
var client = new Client({
  hostname: 'xxxxxxx',
  port:  995,
  tls: true,
  mailparser: true,
  username: 'xxxxx',
  password: 'xxxxx'
});

client.connect(function() {

    //I get an email with attachments
    client.retrieve(4327, function(err, messages){
        if(messages.attachments != null){
        for (var i in messages.attachments) {
            var attachment = messages.attachments[i];
            var data = attachment.content;
            fs.writeFile(attachment.fileName, data)
        }
    }

    })
    client.quit();
})

1 个答案:

答案 0 :(得分:3)

here所示,attachment对象的contentBuffer

messages.attachments[0].content应该为您提供文件(Buffer)。