ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / How to proceed? / Programming
  • Principle
  • Examples
  • Browsing emails via a FOR EACH loop
  • Browsing emails via a WHILE loop
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac CatalystUniversal Windows 10 App
Others
Stored procedures
Principle
To read emails via the IMAP protocol without using a messaging software:
  1. Retrieve the parameters for connecting to your messaging server. These parameters are supplied by your Internet service provider or by your network administrator.
  2. Declare an emailIMAPSession variable and initialize it with the parameters retrieved beforehand.
  3. Connect to the messaging server with EmailStartIMAPSession.
  4. Perform a loop to read the emails from the beginning from the end by using EmailReadFirst and EmailReadNext. The Email.Out variable is set to:
    • True if there is no message to read.
    • False otherwise.
  5. Use an Email variable to retrieve the content of email that was read.
  6. Close the IMAP session by using EmailCloseSession.
Examples

Browsing emails via a FOR EACH loop

MyMessage is Email
MyIMAPSession is emailIMAPSession
 
// Start a simple IMAP session
MyIMAPSession.ServerAddress = "imap.mycompany.us"
MyIMAPSession.Name = "user"
MyIMAPSession.Password = "secret"
 
// Start the IMAP session
IF NOT EmailStartSession(MyIMAPSession) THEN
// Error starting the IMAP session
Error("Unable to start the IMAP session.", ErrorInfo()
ELSE
// Read the messages
FOR EACH MyMessage NOT READ OF MyIMAPSession
// Process the message read
Trace(MyMessage.Subject, MyMessage.Sender, MyMessage.Message)
END
// Disconnect from the session
EmailCloseSession(MyIMAPSession)
END

Browsing emails via a WHILE loop

MyMessage is Email
MyIMAPSession is emailIMAPSession
 
// Start a simple IMAP session
MyIMAPSession.ServerAddress = "imap.mycompany.us"
MyIMAPSession.Name = "user"
MyIMAPSession.Password = "secret"
 
// Start the IMAP session
IF NOT EmailStartSession(MyIMAPSession) THEN
// Error starting the IMAP session
Error("Unable to start the IMAP session.", ErrorInfo()
ELSE
 
// Read the messages
EmailReadFirst(MyIMAPSession, MyMessage)
WHILE NOT Email.Out
// Process the message read
Trace(MyMessage.Subject, MyMessage.Sender, MyMessage.Message)
// Read the next message
EmailReadNext(MyIMAPSession, MyMessage)
END
// Disconnect from the session
EmailCloseSession(MyIMAPSession)
END
Minimum version required
  • Version 15
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 10/27/2022

Send a report | Local help