Implement billing email reminders - node.js

I would like to implement automatic email notification system for recurring billing in Nodejs. E.g. when subscription is about to expire in 5 days or in 24 hours I want to send an email reminder for a user.
I am using Sendgrid as mailing service. Sending an email is a easy task. Question is what is the best practice for implementing such workflow.
I imagine that cronjob could be setup to run every hour or so.
Script is executed that finds all the users with subscriptions which expires in 5 days or 24 hours. Doing so would lead to sending notification every time cronjob is run. I have to track which users are notified already to avoid duplicated emails.

You should create a cron job for that, like I said in comment, daily. After you find and sent emails you can check sendgrid api to make sure email has been delivered.
https://sendgrid.com/docs/Glossary/deliveries.html
You can also make a web hook to check that
https://sendgrid.com/docs/API_Reference/Webhooks/event.html
the rest of implementation in logic.

Related

How to send email for a particular scheduled date and time ? [Schedule Email Feature]

I tried cron jobs for scheduling but it gets triggered for each and every day at that particular time.
Also workaround Gmail API for scheduling, but there isn't a feature in Gmail API
My requirement is to send a scheduled email for the given time by the user.
Here I'm using Postgresql as DB and for backend Nest.js
Kindly help me to figure out this issue.

Intermittently Delay in Receiving Email Messages by Gmail Api

I'm facing intermittently delay with polling email messages via Gmail API from GSuite user's inbox. Those calls origin from automatic jobs and use multiple G-Suite users to disperse the work and avoid reaching Quota limits.
However, there are still delay of at least 3 minutes in reading the email. Investigating message email headers showed neither errors (429) or delay time, nor quota limits are being reached.
I examined the push notification method and I'm limited to use it.
Are limit units calculated according to domain rather than per G-Suite user so I'm indeed reach quota?
What else can cause those delays?
The Gmail API has usage limits per method and per user.
Email sending limits are calculated per user per day, not per domain.
Limit units are calculated from all requests made from your application per day
You can check your quota in the Cloud console, choosing your project and API (in this case Gmail).
In my case, I could clearly see the email inside the 'Sent' folder but the recipient had not got any email, so I knew the limits for using the API had not been crossed. It was spam protection taking a ton of time to figure out if the sent email was spam or not. The most common case would be if your emails are all similar with a link in them. I removed the hyperlink in my template email notification and it started working again without any delay.

Set trial date on stripe dashboard only refer to plans not create them in my app using stripe

Not sure if the title makes sense, I will say this question is very similar to the one I posted yesterday but no response on seen here. I have a user sign up and select a plan, once they are set to said plan there is a trial day limit set using the stripe dashboard. I am not creating the subscriptions via the API. Once the day 30 days are up, how can I tell? Only way I can think of telling is checking if their account is older than 30 days and doesn't have a stripe token/last 4 numbers of their CC. There has to be a better way that is more secure and prevents them from canceling their card and still being able to use the service. I know there is no code in this post and should be, but the only code I think is relevant is in the linked post you should check out.
I should add, where should I put this code in my routes? And I am using node.js, express, swig, and stripe.
What you are looking for is Stripe Events. When an action happens on your account, Stripe issues an "event". You should set up a webhook in your dashboard, and an endpoint on your site or app to capture Stripe Events and process the data that is sent.
Stripe issues two perfect events for what you need: customer.subscription.trial_will_end which fires three days before the trial ends , and customer.subscription.updated which fires in multiple cases, including when the status is changed from trialing to active.
Read through the Stripe docs here to learn more.

Gmail API - Adding an attribute for each mail. Is it possible?

Let's suppose I want to create a tracking time web app and one of the features allows the user to track the time spent sending mails. So, when receiving or sending an email, there would be an option for indicating how long it took the user to send or read that email. Then, from the website of my web app (mytrackingtimeapp.com), the users could create custom charts and reports for listing, for example, all the emails that took him more than 10 minutes to read and were sent in June.
If I had in a database of mine all the emails, this would be as simple as create a column for each email storing that value.
So my question is: would it be possible with the current Gmail API do so?

Scheduled and triggered jobs in Azure

For my Azure app I have a variety of scenarios for needing both scheduled and triggers jobs. Having researched both Azure WebJobs and Scheduler it appears I can accomplish this, but not in the best way possible.
My use cases will go something like:
Weekly email blast (seems right up the alley for Scheduler)
Event invites, dynamically timed based on event's time (I could have
a job check every hour to see if any need to be sent? or at the
event's creation create a Scheduled Job at the specific time, but
what happens if the event changes?)
Reminders based on #2 above
(same issues/questions)
Welcome emails (two versions, one if they
complete a walkthrough and another if they don't: how to manage the
timing of this?)
So basically I see how I can use Azure Scheduler to accomplish all of this, but not in the most efficient way. I would like to see if there's a way to manage Azure Scheduler along with some sort of triggered Jobs based on various criteria, controller by code. Does something like this exist?
Update
To add a bit more information to this,
I'm using Mandrill as these are transactional emails. The things that makes my use case not appropriate for Mailchimp or some automation platform is I have repeat templates I will be sending out (5ish) which are triggered dynamically based on my user's events and various configurations.
Examples:
1) New user registers. If they complete an on-boarding walkthrough they receive one type of welcome email, if they don't complete the on-boarding walkthrough within x minutes they receive an other type of welcome email.
2) An event is created by an admin. At that moment code will comb through all users to see who should be invited based on user's preferences, then send out personalized invites to each user.
Consider using the WebJobs SDK for some of this. For example, you could use an Azure Storage Queue to invoke your web job as event invites are created or modified in your application. You may want to have different queues that different web jobs are triggered from too. For example, one for invites, another for reminders, and one for welcome emails.
The weekly email blast may be a separate scheduled web job in your scenario.
Putting my business cap on, it sounds like you have a need of something that will handle your email marketing/automation. Consider looking at 3rd party products that specialize in this, instead of hand-coding it. Mailchimp # http://mailchimp.com comes to mind. They have a feature called Goal completion more info at: http://blog.mailchimp.com/new-trigger-emails-from-website-traffic/
Alternatively, a monitoring and automation service that my company provides (CloudMonix # http://cloudmonix.com ) allows for automatically kicking off tasks based on some very custom criteria. CloudMonix knows nothing about email marketing, but it can kick-off a Web job or an Azure automation job if some SQL record appeared in the database or a metric published somewhere.

Resources