PC SOFT

ONLINE HELP
FOR WINDEV, WEBDEV AND WINDEV MOBILE

  • Overview of "Simple MAPI"
  • Principle
  • 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
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadApple WatchUniversal Windows 10 AppWindows Mobile
Others
Stored procedures
Overview of "Simple MAPI"
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".
Principle
To send or read messages via Simple MAPI, you must:
  1. Describe a user profile. This user profile must be created in the Microsoft application for email management (MS Exchange client for example).
  2. From the WINDEV application (or from the WEBDEV site), connect to the application for email management (MS Exchange client for example) with EmailStartSession.
  3. Send and read the messages.
  4. 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.
Note: 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:
  1. Open the control panel.
  2. Double-click the "Email" option.
  3. Click the "Display the profiles" button.
  4. In the window named "Choosing a profile", click the "Add" button.
  5. Give a name to the profile. This name will be used in the WINDEV programs.
  6. Select "Add a new email account".
  7. Select the "Microsoft Exchange Server" service.
  8. 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).
EmailStartSession 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.
FUNCTION StartSession(Profile)
// Start the session
SessionNum is int
SessionNum = EmailStartSession(Profile)
IF SessionNum = 0 THEN
Error("The session cannot be started. Error: " + Email.Error)
END
RESULT SessionNum

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[1] = 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
EmailSendMessage(SessionNum, False)
END
// Send the messages from MS Exchange to the email server
IF NOT EmailUpdate(SessionNum) THEN
Error("Problem with MS Exchange. Error:" + Email.Error)
END

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.
Example: 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)
END

// Read the first unread message
IF not EmailReadFirst(SessionNum, "NOT READ") THEN
Error("Error while reading the first message")
END

// Browse the unread messages and display them in a memory table
TableDeleteAll(TABLE_Messages)
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")
END
// Read the next unread message
IF not EmailReadNext(SessionNum, "NOT READ") THEN
Error("Error while reading the next message")
END
END

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.
Example: 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.
PRODEDURE CloseSession(SessionNum)
// Close the session
EmailCloseSession(SessionNum)
Minimum required version
  • Version 9
This page is also available for…
Comments
Click [Add] to post a comment