4D Blog

Home Product Copy, move, and delete emails with IMAP

Copy, move, and delete emails with IMAP

October 27, 2020

Product

Sometimes you need to save certain emails in dedicated mailboxes and other times you want to delete certain emails to keep up your INBOX tidy. The three new functions we’ve added to the IMAP transporter, copy(), move(), and delete() make this a breeze!

HDI IMAPMailCopy

move or copy emails

To move an email, you need to be connected to your mail server and have a mailbox selected. For the following examples, we’ll use the inbox mailbox:

$transporter:=IMAP New transporter($serverInfo)
$boxInfo:=$transporter.selectBox("inbox")

To move all of the emails whose subject contains “4D new feature:” from your current mailbox (“inbox”) to a mailbox named “New features”, use the move() function:

$mailIds:=$transporter.searchMails("subject \"4D new feature:\"")
// Move emails from selected mailbox to destination mailbox
$status:=$transporter.move($mailIds; "New features")

The mails are no longer displayed in the inbox mailbox but rather, in the New features mailbox. Of course, you can also keep them in both mailboxes with the copy() function:

// Copy emails from selected mailbox to destination mailbox
$status:=$transporter.copy($mailIds; "New features")

Delete emails

If you want to delete all of the emails in your “Junk Email” mailbox, just select this mailbox and use the IMAP all keyword with the delete() function:

$boxInfo:=$transporter.selectBox("Junk Email")
// delete all the email in the current mail box
$status:=$transporter.delete(IMAP all)

Note that the delete() function only flags the message as deleted. It won’t be deleted from the IMAP server until you switch the mailbox or close the connection.

Download the HDI above to see the new functions in action!

Discuss

Tags IMAP, Mail, v18 R5, v19

Latest related posts

  • June 16, 2025

    Generate, share and use web sessions One-Time Passcodes (OTP)

  • May 20, 2025

    Automatic Refresh of OEM Build Licenses

  • May 16, 2025

    New class to handle incoming TCP connections

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 Google Listbox Logs Mail 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 Google Listbox Logs Mail 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