4D Blog

Home Product 4D Netkit: Assign Labels & Get Multiple Emails with Gmail API

4D Netkit: Assign Labels & Get Multiple Emails with Gmail API

January 17, 2024

Product

From 4D v20 R4, we are adding a duo of powerful enhancements to the Gmail command set.

The first feature allows you to retrieve several emails simultaneously, and the second one will enable you to manage label emails.

Keep reading for all the details.

HDI Google Manage Mails

Account connection

Before creating an email, 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"})

Add or remove email labels

Labels are used to categorize emails. They are similar to folders in other email systems. But what’s special about labels is that you can assign several labels to the same email. This label can be a custom or system label like INBOX, SPAM, TRASH, UNREAD, STARRED, or IMPORTANT. For example, an email can be labeled as “Work” and “IMPORTANT” with the .update() function:

$status:=$google.mail.update($mailIds; {addLabelIds: ["Work"; "IMPORTANT"]})

In the same way, you can remove labels from emails with the .update() function. For example, if you want to remove the UNREAD label:

$status:=$google.mail.update($mailIds; {removeLabelIds: ["UNREAD"]})

Download multiple emails

If you have several emails to retrieve, you can do it all at once with the .getMails() function:

$mailIds:=$google.mail.getMailIds({labelIds: ["INBOX","UNREAD"]})
// Gets the email according to the collection of mail ID
$mails:=$google.mail.getMails($mailIds)

The .getMails()  can get only 100 emails at once. If you need to get more emails, call this function several times.

In summary, this feature release enriches 4D’s Gmail command set, offering enhanced capabilities such as simultaneous email retrieval and efficient label management.

For detailed implementation, refer to the documentation.

Discuss

Tags 21, 4D NetKit, Google, Mail, v20 R4

Latest related posts

  • May 20, 2025

    Automatic Refresh of OEM Build Licenses

  • May 16, 2025

    New class to handle incoming TCP connections

  • April 29, 2025

    Discover your AI-powered writing assistant in 4D Write Pro

Fabrice Mainguené
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.
  • Deutsch
  • Français
  • English
  • Português
  • Čeština
  • Español
  • Italiano
  • 日本語

Categories

Browse categories

  • 4D View Pro
  • 4D Write Pro
  • 4D for Mobile
  • Email
  • Development Mode
  • 4D Language
  • ORDA
  • User Interface / GUI
  • Qodly Studio
  • Server
  • Maintenance
  • Deployment
  • 4D Tutorials
  • Generic
  • 4D Summit sessions and other online videos

Tags

4D-Analyzer 4D for Android 4D for iOS 4D NetKit 4D Qodly Pro 4D View Pro 4D Write Pro 20 R8 20 R9 Administration Authentication Build application CI/CD Class Client/Server Code editor Collections Compatibility settings Formula Listbox Logs Mail Microsoft 365 Network Objects ORDA PDF Pictures Preemptive Programming Qodly Studio REST Scalability Security Session Source control Speed Spreadsheet Tutorial UI User Experience v20 vscode Web Word processor

Tags

4D-Analyzer 4D for Android 4D for iOS 4D NetKit 4D Qodly Pro 4D View Pro 4D Write Pro 20 R8 20 R9 Administration Authentication Build application CI/CD Class Client/Server Code editor Collections Compatibility settings Formula Listbox Logs Mail Microsoft 365 Network Objects ORDA PDF Pictures Preemptive Programming Qodly Studio REST Scalability Security Session Source control Speed Spreadsheet Tutorial UI User Experience v20 vscode Web Word processor
Subscribe to 4D Newsletter

© 2025 4D SAS - All rights reserved
Terms & Conditions | Legal Notices | Data Policy | Cookie Policy | Contact us | Write for us


Subscribe to 4D Newsletter

* Your privacy is very important to us. Please click here to view our Policy

Contact us

Got a question, suggestion or just want to get in touch with the 4D bloggers? Drop us a line!

* Your privacy is very important to us. Please click here to view our Policy