4D Netkit: Create, delete and update Gmail labels

Gmail labels provide a flexible way to categorize and organize emails, enabling personalized and efficient email management. Their use facilitates easy navigation and identification of messages, offering an enhanced user experience in email handling.

With this last set of functions that includes all the features to manage labels from the 4D v20 R4, you have in 4D NetKit a set of functions to manage your Gmail labels by programming.

HDI Google Manage Labels

Account connection

Before creating a label, we will create an OAuth 2.0 connection object and a Google object.

var $oAuth2 : cs.NetKit.OAuth2Provider
var $google : cs.NetKit.Google
$google:=cs.NetKit.Google.new($oAuth2; {mailType: "JMAP"})

Create a label

Creating a new label is straightforward using the .createLabel() function. For instance, to create a ‘Backup’ label:

$status:=$google.mail.createLabel({name: "Backup"})

Get label information

Retrieve label information, such as name, total message count, and unread messages, with the .getLabel() function:


Update a label

Update a previously created label using the .updateLabel() function. For example, rename it to ‘Backup 2024’:

$status:=$google.mail.updateLabel($labelId; {name:"Backup 2024"})

Delete a label

Deleting a label is done with the .deleteLabel() function:


In conclusion, leveraging the Gmail API’s label management features in 4D offers a seamless way to organize and streamline email-related workflows. The ability to create, retrieve, update, and delete labels effortlessly improves email categorization customization and overall efficiency. Developers can refer to the official documentation for detailed implementation and exploit the full potential of label operations in Gmail’s integration with 4D.

Fabrice Mainguené
• Product Owner •Fabrice Mainguené joined 4D Program team in November, 2016. As a Product Owner, he is in charge of writing the user stories then translating it to functional specifications. His role is also to make sure that the feature implementation delivered is meeting the customer need.After obtaining a Bachelor degree in Computer Science at CNAM, Fabrice joined a small software publishing company as a Windev developer. Then he worked for different companies in industry and trade areas as a Windev and web developer as well as technical advisor on new features.