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.
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
$oAuth2:=cs.NetKit.OAuth2Provider.new($credentials)
$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"})
$labelId:=$status.label.id
Get label information
Retrieve label information, such as name, total message count, and unread messages, with the .getLabel() function:
$info:=$google.mail.getLabel($labelId)
$name:=$info.name
$emailNumber:=$info.messagesTotal
$unread:=$info.messagesUnread
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:
$status:=$google.mail.deleteLabel($labelId)
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.