node package manager
Love JavaScript? Your insights can make it even better. Take the 2017 JavaScript Ecosystem Survey »

s3-emails-to-mongo

What this module does

This simple module takes mail objects stored on AWS S3 from AWS SES and indexes them into your mongo database. You have to pass in the AWS Bucketname as described below and setup your AWS shared authentication and you should be good to go!

How to use

In order to use this module, you must have AWS shared credential set up on your computer. You also must run the configureOptions() function in order to set your AWS S3 Bucket name. You can also choose to overwrite other options in the configuration (more on that below).

const getNewMessages = require('s3-emails-to-mongo');
 
getNewMessages.configureOptions({
    Bucket: 'unique-aws-bucket',
});

Consuming with a promise example:

getNewMessages()
.then((messages) => {
    if (!messages.length) {
        console.log('no new messages!');
    }
    else {
        console.log('new messages added to DB!\n\n', messages);
    }
})
.catch((err) => {
    console.log(err);
});

Callback Example

getNewMessages((messages, err) => {
  if (!err) {
   if (!messages.length) {
      console.log('no new messages!');
    }
    else {
      console.log('new messages added to DB!\n\n', messages);
    }
  } else {
    console.log('err', err);
  }
});

Overwriting Configuration Options

This is the default configuration:

{
    Bucket: '',
    DB: 'Mail',
    MailSchema: {
        headers: false,
        subject: true,
        from: true,
        to: true,
        cc: true,
        bcc: true,
        date: true,
        messageId: true,
        inReplyTo: true,
        'reply-to': true,
        references: false,
        html: false,
        text: true,
        textAsHtml: false,
        attachments: true,
        read: true,
    },
    set: false,
}

You can overwrite any of the above values as long as you give it the same data type it was originally set to. Don't change the set value, it will be automatically changed to true when you run the configureOptions() function.