WhatsApp API integration with Google mail
This link template is used to send notifications to Mail when certain events occur in WhatsApp. As in the case of Google drive, Google mail uses a custom function that will replace the smtp server. Such a solution is used to quickly configure notifications and the security of your mail with such a quick setup.
In the initial setup, you need to specify the address of the function that will be deployed on the Google cloud server. More on this below. We will need an already created mailbox in Google mail and a project in Google cloud. To get started, create a new project in Google cloud or select an existing project.
Billing must be enabled in the project for further correct connection. Google itself will also remind you about this when trying to connect the API.
Next, you need to go to the project libraries section, find and connect the “Cloud Build API" - you will need it to deploy the function.
You need to create a new Google function that will resave the file to Google drive. To do this, go to the address, select the project of interest at the top and create a new function.
In the function settings, we specify the region that is convenient for us, set the name of the function (preferably a random name from 16 to 32 characters), you can immediately copy the full url of the link to the widget in the Chat API. Below in the function settings we specify? that authentication is also allowed for unauthorized users. Click "save". Below we set 256 megabytes. click "continue".
Copy the index.js and package.json from the project https://github.com/chatapi/chainapi-google-mail in the window that opens, respectively.
Next, you need to change the “from" parameter in the index.js to your Google e-mail address from which the newsletter will be sent.
In the “pass" parameter in index.js you need to specify the password to your mailbox (don't worry, this file is only available to you, no one will know your password), or if you have two-step authorization enabled, you need to perform the actions described here and then specify the created password for the application in the password field.
If you don't want the files to be automatically available to all users, in the ShareFile constant inside index.js must be set to false.
Also, to access the function to the Google smtp server, you need to provide access for non-secure applications to your email, for this you need to go to https://myaccount.google.com/lesssecureapps from the intended mailing address and allow applications access.
In the upper right corner of the function settings, you need to specify your sendMail function at the entry point (entrypoint).
Click the deploy button and wait for the process to complete.
After that, you can continue the initial configuration in the API chains. If you forgot to enter the address of the function - wait for the completion of its deployment, go to edit and copy the address. After that, you will need to specify in the dynamic data to which address you will send the data, with which text and with which header. For a successful request, either the Html parameter or the text parameter must be present.
A good idea for technical notifications is to transfer the subject of the letter and the recipient (to) to static data and specify the subject and address of the letter manually, and make the body of the letter dynamic (for example, specify the path to the body of the message in text).
In the response, you can find data of the following type
Since the nodeMailer package is used, a partial description of the response options can be found at https://nodemailer.com/smtp/