4D Blog

Home Product Receive emails with POP3 protocol

Receive emails with POP3 protocol

February 12, 2020

Product

4D v18 introduced an easy to use and powerful new way to create and send emails. A way that lets you send eye-catching emails based on HTML (with images, videos, and attachments), using just a few lines of code.  In 4D v18 R2, we’ve added the ability to locally download your emails and remove them from your email server. In this blog post, we’ll go through the new possibilities this offers. 

The new POP3 New transporter command allows you to use the POP3 protocol to manage email. The Post Office Protocol (POP) is a standard protocol to retrieve email from a mail server. It’s useful for actions such as connecting to a POP3 server, retrieving messages to process automatically and/or store in your local database, and deleting them from the server.

HDI POP3 mailbox downloading

Create a pop3 Transporter

As with SMTP, when using the POP3 protocol you first need to create a POP3 transporter (via the POP3 New transporter command):

$server:=New object
$server.host:="yourPOP3host.com"
$server.port:=995
$server.user:="4D.POP3@mail.com"
$server.password:="XXXXXX"
// Create a transporter from your server information
$POP3 transporter:=POP3 New transporter($server)

Mail information

You can get information about all of the messages in your mailbox with the getMailInfoList() method of your POP3 transporter object. The returned list contains, in particular, a message number identifying each email during the POP3 transaction:

$mailInfos:=$POP3 transporter.getMailInfoList()

If you need information for just a single message, you can use also the getMailInfo() method … just pass the message number in parameter:

$mailInfo:=$POP3 transporter.getMailInfo($mailNumber)

receive email

You can download all messages or specific messages using the getMail() method. To download a specific message, simply pass the message number returned by getMailInfoList() as a parameter to this method. The following example demonstrates how to download all of the messages in your mailbox:

$mailInfos:=$POP3 transporter.getMailInfoList()
$mails:=New collection
For each ($mail;$mailInfos)
  // Download email 
  $mails.push($transporter.getMail($mail.number))
End for each

delete email

You can flag a message to be deleted during the session closure with the delete() method. In the same manner as the getMail() method, pass the message number returned by the getMailInfoList() as a parameter. For example, if you want to download and delete all of the messages in your mailbox:

$mailInfos:=$POP3 transporter.getMailInfoList()
For each ($mailInfo;$mailInfos)
  // Download email 
  ProcessMail($POP3 transporter.getMail($mailInfo.number))
  
  // Flag messages "to be deleted at the end of the session"
  $POP3 transporter.delete($mailInfo.number)
End for each
// Force the session closure to delete the messages flagged for deletion
$POP3 transporter:=Null

Mailbox information

You can get the number of emails in your mailbox and the size of the mailbox with the getBoxInfo() method:

$boxInfo:=$POP3 transporter.getBoxInfo()
ALERT("Size: "+String($boxInfo.size)+" - Count: "+String($boxInfo.mailCount))

log transaction

As with SMTP logs, you can log all your POP3 transactions. There are two ways to create your log:

  • Run a POP3 log on the server – click the “Start Request and Debug Logs” button on your 4D Server
  • Log a specific transaction (during debugging, for example) – use the logFile property of the POP3 transporter object:

 

$server.host:="yourpop3server.com"
$server.user:="login"
$server.password:="psw"
// Enter the path of the log file you want to create
$server.logFile:="C:\\tmp\\POP3Log.txt"
$transporter:=POP3 New transporter($server)

 

You can test all of these commands with the HDI above.

Discuss

Tags Mail, POP3, Programming, v18 R2, v19

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