Latenode integration with Gmail for sending messages
Send emails from Gmail via webhook

With the Latenode service you can send emails using a webhook
First, let's get an authorization token for Google
Go to our article on how to get a Google token in Developer OAuth 2.0 Playground;
Setting up the script in Latenode
Stop the routine, automate your mail responses with Latenode
Go to the "Latenode" service page;
Create a new project;
![]()
Create a component "Webhook", copy its address into notepad too;
Create a "JavaScript" component;
Copy the javascript code from this page;
сonst fromAdress = <span class="hljs-string">"[email protected]"</span>; <span class="hljs-comment">// From which address to send, from whom (don't forget to change it to your own)</span>
<span class="hljs-keyword">const</span> messageTarget = data[<span class="hljs-string">"{{1.body.target}}"</span>]; <span class="hljs-comment">// To which address to send, to whom(don't forget to change to your own value)</span>
<span class="hljs-keyword">const</span> messageTitle = data[<span class="hljs-string">"{{1.body.title}}"</span>]; <span class="hljs-comment">// Message header(be sure to change to your own value)</span>
<span class="hljs-keyword">const</span> messageText = data[<span class="hljs-string">"{{1.body.message}}"</span>]; <span class="hljs-comment">// Message text (don't forget to change to your own value)</span>
<span class="hljs-keyword">const</span> token = data[<span class="hljs-string">"{{1.body.token}}"</span>] <span class="hljs-comment">// Authorization token (do not forget to change to your own value)</span>
<span class="hljs-comment">// Encryption of all necessary information in base64 with replacement with safe characters</span>
<span class="hljs-keyword">const</span> resultEncodeString = <span class="hljs-title function_">btoa</span>(
<span class="hljs-string">`From: <span class="hljs-subst">${fromAdress}</span>\r\n`</span> +
<span class="hljs-string">`To: <span class="hljs-subst">${messageTarget}</span>\r\n`</span> +
<span class="hljs-string">`Subject: <span class="hljs-subst">${messageTitle}</span>\r\n\r\n`</span> +
<span class="hljs-string">`<span class="hljs-subst">${messageText}</span>`</span>
).<span class="hljs-title function_">replace</span>(<span class="hljs-string">`/\+/g`</span>, <span class="hljs-string">'-'</span>).<span class="hljs-title function_">replace</span>(<span class="hljs-string">`/\//g`</span>, <span class="hljs-string">'_'</span>).<span class="hljs-title function_">replace</span>(<span class="hljs-string">`/=+$/`</span>, <span class="hljs-string">''</span>);
<span class="hljs-keyword">return</span> {
fromAdress,
token,
resultEncodeString
}
Save all information in the node;
Run any rest client (Postman, Insomnia), you can do in a browser but then you need to pass the information in the query parameters;
Import the code below into it and change the values of the parameters to your own;
<span class="hljs-string">curl</span> <span class="hljs-built_in">--request</span> <span class="hljs-string">POST</span> \
<span class="hljs-built_in">--url</span> <span class="hljs-string">'[Your webhook address]'</span> \
<span class="hljs-built_in">--header</span> <span class="hljs-string">'Accept: application/json'</span> \
<span class="hljs-built_in">--header</span> <span class="hljs-string">'Content-Type: application/x-www-form-urlencoded'</span> \
<span class="hljs-built_in">--data</span> <span class="hljs-string">target</span>=<span class="hljs-string">'[The address to which we are sending the message]'</span> \
<span class="hljs-built_in">--data</span> <span class="hljs-string">'title=Hello World![The title of your message]'</span> \
<span class="hljs-built_in">--data</span> <span class="hljs-string">'message=I use Latenode to send this message from Gmail![The text of your message]'</span> \
<span class="hljs-built_in">--data</span> <span class="hljs-string">token</span>=<span class="hljs-string">'[Your token that you received]'</span>
Start the project;
Invoke Webhook with your rest client;
Open the "JavaScript" component again;
Change the values to your own using the Latenode side menu, in the comments of the code says what you need to change (usually just text in square brackets), after comments you can delete;
![]()
Save changes in the node;
Next we create the "HttpRequest" component;
![]()
In the endpoint address, insert the transmittable address of our Gmail:
https:<span class="hljs-regexp">//gm</span>ail.googleapis.com<span class="hljs-regexp">/gmail/</span>v1<span class="hljs-regexp">/users/</span>[Select Latenode fromAdress from JS <span class="hljs-keyword">in</span> the side menu]<span class="hljs-regexp">/messages/</span>send
Select "Post" as the method of choice;
In body "raw";
{raw:<span class="hljs-string">"[select resultEncodeString from JS in the side menu]"</span>}
"Headers";
Accept: application/<span class="hljs-type">json</span>
Content-<span class="hljs-keyword">Type</span>: application/<span class="hljs-type">json</span>
<span class="hljs-keyword">Authorization</span>: Bearer [<span class="hljs-keyword">select</span> the Latenode token <span class="hljs-keyword">from</span> JS <span class="hljs-keyword">in</span> the side menu]
You can import a ready-made one using "Create from example (CURL)";
<span class="hljs-string">curl</span> <span class="hljs-built_in">--request</span> <span class="hljs-string">POST</span> \
<span class="hljs-built_in">--url</span> <span class="hljs-string">'https://gmail.googleapis.com/gmail/v1/users/YOUR_EMAIL/messages/send'</span> \
<span class="hljs-built_in">--header</span> <span class="hljs-string">'Accept: application/json'</span> \
<span class="hljs-built_in">--header</span> <span class="hljs-string">'Authorization: Bearer TOKEN_HERE'</span> \
<span class="hljs-built_in">--header</span> <span class="hljs-string">'Content-Type: text/plain'</span> \
<span class="hljs-built_in">--data</span> <span class="hljs-string">'{raw: "ENCODE_STRING"}'</span>
Press "Save";
To check use any service temp mail(example);
![]()
Copy the generated email address;
Insert it in the target field of the parameter in the rest client, if you did it through the usual get then change the same query parameter;
Call request;
![]()
Let's go check the mailbox;
Hope you got your message;)
Stop the routine, automate your mail responses with Latenode
Useful Links:
Basic:
Information:



