dwyl / sendemail

💌 Simplifies reliably sending emails from your node.js apps using AWS Simple Email Service (SES)
181 stars 26 forks source link

Documentation for batch email sending ? #41

Open sahanDissanayake opened 8 years ago

sahanDissanayake commented 8 years ago

@dwyl any thoughts ?

nelsonic commented 8 years ago

@sahanDissanayake how many emails do you want to send per batch? What type of email? e.g: newsletter? will the email not include any personalisation? (i.e. all the same?)

sahanDissanayake commented 8 years ago

Hi Nelson,

This is my scenario.

My situation is farily simple.. Lets me explain. I have clients.. lets say 100 My clients have customers lets say 1000 each So one of my clients wants to send out a newsletter to their 1000 customers using my app.

So each email will have the user first name. That is the only personalisation for the email that needs doing.

nelsonic commented 8 years ago

Ok, so you're sending an individual email to each recipient. Surely, you can create a loop to send the emails?

// GET list of recipients from database, iterate over list and send to each
database.get('recipients', (err, list) => {
  // handle error
  list.forEach(recipient => {
    // see: https://github.com/dwyl/sendemail#4-send-an-email
    sendEmail('newsletter', recipient, (err, result) => {
      // update the "sent/history" table for each recipient
    });
  }
}

Provided you have authenticated your AWS account you should be able to send as many emails as you like using this process.

If you need a more detailed example, let us know.

sahanDissanayake commented 8 years ago

Awesome. but sending a 1000 emails a second in a loop fashion is not a bad practice right ? I would like to hear some opinion on this too please ?

If all well.. I'm happy to close this issue

nelsonic commented 8 years ago

@sahanDissanayake very good question! if you are sending thousands of emails per second, you may need consider limiting, to avoid exhausting your stack. there are two ways you can do this: a. write your own asynchronous limit code by following an example: http://stackoverflow.com/questions/9539886/limiting-asynchronous-calls-in-node-js b. use Async http://caolan.github.io/async/docs.html#.parallelLimit

If you need a code example, please let us know. 👍

sahanDissanayake commented 8 years ago

Awesome.. I will give you an update soon 👍 with in the next 48 hours

If you need a code example, please let us know.

@nelsonic I mean I would love to see some pro code if its not too much trouble 😇

sahanDissanayake commented 8 years ago

@nelsonic should I expect a code sample from you with the async module ?

Also could you tell me how many concurrent emails you send currently in your company please using this package ?

nelsonic commented 8 years ago

@sahanDissanayake really sorry to no reply sooner, do you still need help?