Automated birthday wishes


[Photo by Adi goldstein on unsplash.com]

Hello world! Birthday is special for everyone, and wishes on birthday make everyone happy. We take a break to wish birthday to our near and dear once, personally. 
But in our contact there are many more people, we cannot wish them on their birthday, and we cannot remember everyone’s birth date.

There are many channels which are there to remind you about birthdays of your contacts, but what if we can automate the birthday wishes for everyone, we can write our own custom bot to send birthday wishes to our friends/ contacts.

Here is the one way we can do that with Google scripts. So let’s get started.

Automatically send birthday wish 
Setup: For this you need to add emailed and birth date to your Google contacts. You can add these details to your phone contacts that will automatically get sync with Google contacts.
Then go to google script page and create new project.
Here you will get a Code.gs file.

In this file we need to do 2 things.
1. Get current date.
2. Fetch all contacts whose birthdate is today.


1. To get current date [date and month ]
  var today = new Date();
  var month = today.getMonth();

2. Now we have to fetch the contacts having birthday today.
For that we can use fetch contact by date.

var contactsHavingBirthdayToday = ContactsApp.getContactsByDate(m, today.getDate(),ContactsApp.Field.BIRTHDAY);

Now we have to iterate all these contacts, and send a birthday wish mail.

For that we can use:

GmailApp.sendEmail();

Function.



Complete code is shared at <https://github.com/buildbetterapps/BirthdayMail > you just need to replace your email with “youremail@gmail.com” and all done.

Our bot is ready.

But this code will run only when run the code, but we want to execute this code every day. For that we need to create trigger that will trigger this code every day. At specific time.

For this click on the trigger icon from the toolbar, ad click on add trigger, select day timer and a suitable time.

Now this code will trigger every day and send a birthday wish to your contact.

You can modify the default mail with some attractive text and images, you can also replace the email with a text SMS or with whatsapp message by integrating with other APIs.

Comment below what you have done extra with this. Happy coding. 


Comments