Skip to content
Browse files

Add basic script

  • Loading branch information...
1 parent 1602967 commit 95d8f8e243881787c56d4de817c63143fc51a0c2 @BerkeleyTrue BerkeleyTrue committed
Showing with 54 additions and 2 deletions.
  1. +3 −0 .gitignore
  2. +5 −2 package.json
  3. +46 −0 src/index.js
View
3 .gitignore
@@ -1 +1,4 @@
node_modules
+.env
+data.json
+emails.json
View
7 package.json
@@ -2,7 +2,8 @@
"name": "massification",
"version": "0.0.1",
"description": "An emailing service built on Amazon SES and Node",
- "main": "index.js",
+ "main": "lib/index.js",
+ "repository": "https://github.com/FreeCodeCamp/massification.git",
"scripts": {
"test": "echo 'You did it!'"
},
@@ -12,9 +13,11 @@
"author": "Berkeley Martinez <Berkeley@RoboTie.com> (http://RoboTie.com)",
"license": "BSD-3-Clause",
"dependencies": {
+ "dotenv": "^1.2.0",
"nodemailer": "^1.8.0",
"nodemailer-ses-transport": "^1.3.0",
- "nodemailer-smtp-pool": "^1.1.3"
+ "nodemailer-smtp-pool": "^1.1.3",
+ "rx": "^4.0.6"
},
"devDependencies": {
"babel": "^5.8.23",
View
46 src/index.js
@@ -0,0 +1,46 @@
+import { Observable, Schedular } from 'rx';
+import nodemailer from 'nodemailer';
+import ses from 'nodemailer-ses-transporter';
+import dotenv from 'dotenv';
+import emails from 'emails.json';
+import data from 'data.json';
+
+dotenv.load();
+
+const options = {
+ accessKeyId: process.env.access_key,
+ secretAccessKey: process.env.priv_key,
+ rateLimit: 10000
+};
+
+const mailOptions = {
+ from: "You <you@example.com>",
+ subject: data.subject,
+ text: data.text
+};
+
+const transporter = nodemailer.createTransport(ses(options));
+const send$ = Observable.fromNodeback(transporter.sendMail, transporter);
+
+Observable.from(emails)
+ // batch every 10000
+ .bufferWithCount(10000)
+ // wait 1 sec between batches
+ .delay(1000)
+ .flatMap(emails => {
+ const filledOptions = Object.assign(
+ {},
+ mailOptions,
+ { emails: emails.join(', ').replace(/,$/, '') }
+ );
+ return send$(filledOptions);
+ })
+ .count()
+ .subscribe(
+ count => console.log('sent %d so far', count),
+ err => throw err,
+ () => {
+ console.log('process complete');
+ process.exit(0);
+ }
+ );

0 comments on commit 95d8f8e

Please sign in to comment.
Something went wrong with that request. Please try again.