You are a firm that sells products or service, for example you are a store that sells perfum. You are trying to win the loyalty of your clients, so that you're selling more to loyal clients, who are an interesting market for you.
It's Valetin's day in three weeeks and for that event you want your men client to offer a new gift, eg. a perfum, to their loved one. But the hardest part is that your clients that have registered long time ago still come to your store. So your thinking of make better offer to them. You are in this case using a based-time loyalty system using your database. For that, we will send them a email reminding them that Valentin's day arrives soon and that if they buy a perfum for women they will have a gift in return.
Let's see how you do this!
You start by checking the database you have of your client. Here we are using Firebase for our client's data. I recommend you using Firebase for such data.
You can check how it really work on Firebase
So let's have our data base like this:
You can see that we have all the information we need in our database: name, registred date, email, gender.
Now we can querry for men clients to send mails only to men. Here is an example of how to querry a data, based on Gitch and using our database:
Then, as our idea is based on the duration since the date of registration (so that we can offer better gifts to old clients), we need to calculate that duration. We first need to have the current time. For example, we can use the simple method explain in this article.It is simple in this case to comput the difference, using javascript mathematic language.
At this stage, we know to who we will send mails, we knows if there are old or young clients for us, determining the gifts we will offer them, we also know their mail address (which we can querry easily).
Last but not least, we send the mails. We can do this by using Nodemailer which is a Node.js module which facilitate sending mail to others. On the website, you can have all the information you need to code the sending form. Here is an extract:
Of course, as we are sending mail to different people, we will use a function to personnalize the different elements (name, gift, ... or even specific text).
And we are done!