freetier
v1.0.1
Published
A JavaScript SDK for free services on the Internet.
Downloads
9
Readme
freetier
A JavaScript SDK for free services on the Internet.
This SDK package allows developers to consume only free tier plans from internet service vendors(AWS SES, SendGrid etc.). It will automatically swith to other services when one is exceeding the free tier usage quota.
It's highly recommended that you should switch to the paid plans for more stable and comprehensive services from the vendors once your project/business starts to have decent traffic. And you can still use this SDK as a service integration tool for paid plans.
Sending email
const { sendEmail } = require('freetier');
/** This function will send email using only freetier plans provided by ElasticEmail and SendGrid
* Make sure you have both ElasticEmail and SendGrid accounts setup and timezone configured before
* using this function
*/
sendEmail({
to: 'RECIPIENT_EMAIL',
from: 'SENDER_EMAIL',
subject: 'subject',
message: 'message',
recipient: 'recipient',
sender: 'sender',
}, {
elasticEmail: { apiKey: elasticemailApiKey, dailyLimit: elasticemailDailyLimit },
sendGrid: { apiKey: sendgridApiKey, dailyLimit: sendgridDailyLimit },
}).then(data => {
console.log(data);
}).catch(err => {
console.log(err);
});
You can also use ElasticEmail or SendGrid client directly
const { ElasticEmail, SendGrid } = require('freetier/email');
const ee = new ElasticEmail('API_KEY');
ee.getUsage(from, to).then(data=>{
...
}).catch(err=>{
...
})
ee.sendEmail(to, from, subject, message, recipient, sender, replyTo).then(data=>{
...
}).catch(err=>{
...
})
const sg = new SendGrid('API_KEY');
sg.getUsage(from, to).then(data=>{
...
}).catch(err=>{
...
})
sg.sendEmail(to, from, subject, message, recipient, sender, replyTo).then(data=>{
...
}).catch(err=>{
...
})
| Class | Method | Arguments | Return | |-------|--------|-----------|--------| | email/elasticemail/ElasticEmail | getUsage | from: String|Required|YYYY-MM-DDto: String|Required|YYYY-MM-DD | Promise | | email/elasticemail/ElasticEmail | sendEmail | to: String|Required|recipient emailfrom: String|Required|Sender emailsubject: String|Required|Email subjectmessage: String|Required|Email content (HTML allowed)recipient: String|Optional|Recipient namesender: String|Optional|Sender namereplyTo: String|Optional|Reply-to email | Promise | | email/sendgrid/SendGrid | getUsage | from: String|Required|YYYY-MM-DDto: String|Required|YYYY-MM-DD | Promise | | email/sendgrid/SendGrid | sendEmail | to: String|Required|recipient emailfrom: String|Required|Sender emailsubject: String|Required|Email subjectmessage: String|Required|Email content (HTML allowed)recipient: String|Optional|Recipient namesender: String|Optional|Sender namereplyTo: String|Optional|Reply-to email | Promise |
Integrations with vendors
Make sure you have the correct timezone setting on all vendors' dashboard page, otherwise the auto switch of email providers won't work properly
- SendGrid Free 100 emails/day
- ElasticEmail Free 100 emails/day
Unit testing
Make sure you have a .env file with api keys configured.
sendgridApiKey=OBTAIN_THIS_FROM_SENDGRID_DASHBOARD
elasticemailApiKey=OBTAIN_THIS_FROM_ELASTICEMAIL_DASHBOARD