Processes incoming csv and xlsx mail attachments and notifies node.js with the files converted to json
Built on the popular mail-notifier module by jcreigno, this module aims to provide streamlined attachment handling for CSV and Excel XLSX files. When a new mail arrives, it is scanned for attachments, csv, xlsx, and txt files will be converted into json and a 'attachment' event will be emitted.
This module will also handle .zip
files. Each file within the zip directory will be parsed and a separate event for each file will be emitted.
Watch for attachments:
var attachmentNotifier = require('mail-attachment-notifier');
const imap = {
user: "yourimapuser",
password: "yourimappassword",
host: "imap.host.com",
port: 993, // imap port
tls: true,// use secure connection
tlsOptions: { rejectUnauthorized: false },
directory: "/tmp"
};
var listenAttachments = attachmentNotifier(imap);
listenAttachments.on('attachment', data => console.log(data));
listenAttachments.start();
listenAttachments.stop();
$ npm install mail-attachment-notifier
Configuration built on mail-notifier implementation
The constructor function creates a new attachmentNotifier
. Parameter provide options needed for imap connection.
config
:
host
: imap server hostport
: imap server port numberuser
: imap user namepassword
: imap passwordtls
: need a tls connection to servertlsOptions
: seetls
module optionsmarkSeen
: mark mail as read defaults to truebox
: mail box read from defaults to 'INBOX'search
: search query defaults to ['UNSEEN']directory
:write file location, default to "/tmp"
Start listening for incomming mail/attachments.
Stop listening and close IMAP connection.
This module relies heavily on node-imap. For more advanced usage, please consider using it directly.