KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Smart Email Classification with Dynamic Label Management
PRODUCT: 4D | VERSION: 20 R | PLATFORM: Mac & Win
Published On: September 26, 2025
Take Gmail label management to the next level using 4D NetKit's Google class by creating status-driven labels automatically. Instead of static labels, build dynamic ones that reflect your workflow timeline:

Create a Label :


Generate a custom label in one call:

$status:=$google.mail.createLabel({name: "Processing"})
$labelId:=$status.label.id


Label details such as name, total messages, and unread count are retrieved with:

$info:=$google.mail.getLabel($labelId)
ALERT("Label "+$info.name+" | Total: "+String($info.messagesTotal)+" | Unread: "+String($info.messagesUnread))

Modify Label Properties :


User-type labels support updates to name, visibility, or color:

$google.mail.updateLabel($labelId; {name: "Follow-Up"})

Smart Label Assignment Based on Email Content :


The following example demonstrates how to automatically assign labels based on the content of an email subject, assigning the "Finance" and "To-Review" labels to emails that contain "invoice" in their subject.

// Analyze subject and set dynamic labels
If (Position("invoice"; Lowercase($email.subject))>0)
   // Add both "Finance" and "To-Review" labels
   var $labelsToAdd : Collection
   $labelsToAdd:=New collection("Finance"; "To-Review")
   $google.mail.update($mailIds; {addLabelIds: $labelsToAdd})
End if

// Remove obsolete status label
$google.mail.update($mailIds; {removeLabelIds: ["Pending-Approval"]})


This approach transforms static email organization into a dynamic system that automatically tracks email processing stages through 4D NetKit's Gmail integration.