banana
Banana is a simple mailing library meant to reduce overhead when developing backend services that involve sending some type of email to one (or many) user.
Usage
First, you'll want an instance of a Banana, so just hit it with a little bit of this:
; const banana = service: 'gmail' templatePath: 'src/templates' auth: user: 'foo@bar.edu' pass: 'password' ;
And there you have it, your very own Banana!
So, about templatePath
, it's essentially a folder with a collection of .handlebars
files, you can read more about handlebars here.
Here's an example of a .handlebars
file, let's shove it into src/templates/hi.handlebars
:
Hi {{name}}, I'm a banana!
Now let's send an email using that template with our Banana.
First, let's make a list of our buddies and the emails we'll send them:
const davidName = 'David, the boy'; const davidMail = to: 'david@bar.edu' subject: `Hey !` template: 'hi' // we can omit .handlebars context: name: davidName // These are the variables inside the double curly braces in our template! ; const carlosName = 'Carlos, the other boy'; const carlosMail = to: 'carlos@bar.edu' subject: `Hey !` template: 'hi' // we can even use different templates in the same call! context: name: carlosName ;
Now that we have our friends' message objects all nice and ready, let's shoot those emails out!
banana;
And they'll get this nice little message:
Hi David, the boy, I'm a banana!Hi Carlos, the other boy, I'm a banana!