- Overview of "Simple MAPI"
- Details of different steps
- Step 1: Creating a user profile
- Step 2: Starting an email session
- Step 3: Sending emails
- Step 3 bis: Reading the emails
- Step 4: Closing the email session
Managing the emails with "Simple MAPI"
Overview of "Simple MAPI"
is used to simplify the management of the emails received at the hosting company. When an email is read, it is automatically loaded in the local message box and deleted from the server (at the hosting company).
All the characteristics required to manage the emails (POP3 protocol, SMTP protocol, remote access, etc.) are grouped in the "User Profile".
With the email functions of WLanguage, a WINDEV application or a WEBDEV site can directly handle the emails managed in an application that is using "Simple MAPI".
To send or read messages via Simple MAPI
, you must:
- Describe a user profile. This user profile must be created in the Microsoft application for email management (MS Exchange client for example).
- From the WINDEV application (or from the WEBDEV site), connect to the application for email management (MS Exchange client for example) with EmailStartSession.
- Send and read the messages.
- Close the session to the application for email management (MS Exchange client for example) with EmailCloseSession.
Details of different steps
Step 1: Creating a user profile
The user profile is used to configure the application for email management (MS Exchange client for example).
The following elements are defined in the user profile:
- the SMTP protocol used,
- the POP3 protocol used,
- the different communication services used. To use the "email" functions of WLanguage, the user profile must use the Microsoft Exchange Server.
: A profile must be created for each different user or email account. The profile name will be used to start the email session with EmailStartSession
To create a profile:
- Open the control panel.
- Double-click the "Email" option.
- Click the "Display the profiles" button.
- In the window named "Choosing a profile", click the "Add" button.
- Give a name to the profile. This name will be used in the WINDEV programs.
- Select "Add a new email account".
- Select the "Microsoft Exchange Server" service.
- Enter the name of Microsoft Exchange server.
Step 2: Starting an email session
An email session is started by EmailStartSession
. This function must be the first "email" function used in your WINDEV application (or in your WEBDEV site).
returns the session identifier. This identifier will be used by all the WLanguage functions for email management.
Example: The following procedure is used to start an email session from a profile. If an error occurs, the Email.Error variable is used to identify the error.
// Start the session
SessionNum is int
SessionNum = EmailStartSession(Profile)
IF SessionNum = 0 THEN
Error("The session cannot be started. Error: " + Email.Error)
Step 3: Sending emails
The following functions are use to send emails via Simple MAPI:
- EmailSendMessage: this function is used to place the message in the out-box of the application for email management (out-box of the MS Exchange client for example).
- EmailUpdate: this function is used to synchronize the email server and the application for email management: the new incoming emails are automatically transferred into the in-box, the emails found in the out-box are sent.
For more details, see: Preparing to send an email
Example: The following code is used to send all the emails found in a memory table ("TABLE_TOSEND") via the MS Exchange client. Each table row corresponds to an email.
For each email, the information found in the memory table is transferred into the email structure and the email is sent. Then, the email server is updated.
I is int
FOR I = 1 _TO_ TableCount(TABLE_TOSEND)
// The email is sent to a single person
Email.NbRecipient = 1
Email.Recipient = ExtractString(TABLE_TOSEND[I], 1)
// Subject and message
Email.Subject = ExtractString(TABLE_TOSEND[I], 2)
Email.Message = ExtractString(TABLE_TOSEND[I], 3)
// No attached file
Email.NbAttach = 0
// Send the message to MS Exchange
// Send the messages from MS Exchange to the email server
IF NOT EmailUpdate(SessionNum) THEN
Error("Problem with MS Exchange. Error:" + Email.Error)
Step 3 bis: Reading the emails
Reading the emails via Simple MAPI is performed by:
- EmailUpdate: this function is used to synchronize the email server and the software for email management: the new incoming emails are automatically transferred into the in-box, the emails found in the out-box are sent.
- the functions for reading emails (EmailReadFirst, EmailReadNext, etc.): these functions are used to initialize the email structure of WLanguage with the characteristics of the email currently read (sender, subject, etc.).
For more details, see: Reading an email
: The following code is used to read the emails. The incoming emails are stored in a memory table ("TABLE_Messages"). The SessionNum variable corresponds to the identifier of the session. In this example, the incoming messages are deleted from the inbox and from the email server by EmailDeleteMessage
// Receives the pending messages found on the email server
IF not EmailUpdate(SessionNum) THEN
Error("Problem with MS Exchange. Error: " + Email.Error)
// Read the first unread message
IF not EmailReadFirst(SessionNum, "NOT READ") THEN
Error("Error while reading the first message")
// Browse the unread messages and display them in a memory table
WHILE not Email.Out
// The reception date, the address of the sender and the message
// are assigned to the table
TableAdd("TABLE_Messages", Email.ReceiveDate + TAB +...
Email.SenderAddress + TAB + Email.Message)
// Delete the message
IF not EmailDeleteMessage(SessionNum) THEN
Error("Error during the deletion. The message was not deleted")
// Read the next unread message
IF not EmailReadNext(SessionNum, "NOT READ") THEN
Error("Error while reading the next message")
Step 4: Closing the email session
When the management of incoming and outgoing emails is completed, that session is closed by EmailCloseSession
. This function must be the last "email" function used.
: The following code is a procedure used to close an email session. In this code, the SessionNum
variable corresponds to the session identifier returned by EmailStartSession
// Close the session
This page is also available for…
Click [Add] to post a comment