|
|
|
|
|
- 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 emails
- Step 4: Ending the email session
Managing emails with "Simple MAPI"
Overview of "Simple MAPI" Simple MAPI simplifies management of 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 provider). All the characteristics required to manage the emails (POP3 protocol, SMTP protocol, remote access, etc.) are grouped in the "User Profile". Thanks to WLanguage's email functions, a WINDEV application or WEBDEV site can directly handle emails managed in an application 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 for example).
- From the WINDEV application (or from the WEBDEV website), 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.
Remark: It is necessary to create as many profiles on the workstation as there are different users or e-mail accounts.. 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 To start an email session, use 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 opens an e-mail session from a profile. If an error occurs, the Email.Error variable is used to identify the error. FUNCTION OuvertureSession(Profil)
NumSession is int
NumSession = EmailStartSession(Profil)
IF NumSession = 0 THEN
Error("La session n'a pas pu être ouverte. Erreur: " + Email.Error)
END
RETURN NumSession
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 synchronizes the e-mail server and the e-mail management application: new e-mails received are automatically transferred to the IncomingData inbox, and e-mails in the outbox are sent..
For more details on email creation, see: Preparing to send an email. Example: The following code sends all emails present in a table populated programmatically (table "TABLE_AENVOYER") via the MS Exchange client.. Each table row corresponds to an email. For each email, the information in the Table control is transferred to the email structure, and the email is sent. Then, the email server is updated. I is int
FOR I = 1 _TO_ TableCount(TABLE_AENVOYER)
Email.NbRecipient = 1
Email.Recipient[1] = ExtractString(TABLE_AENVOYER[I], 1)
Email.Subject = ExtractString(TABLE_AENVOYER[I], 2)
Email.Message = ExtractString(TABLE_AENVOYER[I], 3)
Email.NbAttach = 0
EmailSendMessage(NumSession, False)
END
IF NOT EmailUpdate(NumSession) THEN
Error("Problème avec MS Exchange. Erreur:" + Email.Error)
END
Step 3 bis: Reading emails Reading the emails via Simple MAPI is performed by: - the EmailUpdate function: this function synchronizes the email server and the email management software used: new emails received are automatically transferred to the IncomingData inbox, and emails in the outbox are sent.
- email reading functions (EmailReadFirst, EmailReadNext, etc.): these functions initialize the WLanguage email structure with the characteristics of the email currently being read (email author, subject, etc.).
For more details on reading emails, see: Reading an email. Example: The following code reads emails. Incoming emails are stored in a Table control populated programmatically ("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.
IF NOT EmailUpdate(NumSession) THEN
Error("Problème avec MS Exchange. Erreur: " + Email.Error)
END
IF NOT EmailReadFirst(NumSession,"NON LUS") THEN
Error("Erreur lors de la lecture du premier message")
END
TableDeleteAll(TABLE_Messages)
WHILE NOT Email.Out
TableAdd(TABLE_Messages, Email.ReceiveDate + TAB +...
Email.SenderAddress +TAB +Email.Message)
IF NOT EmailDeleteMessage(NumSession) THEN
Error("Erreur lors de la suppression. Le message n'a pas été supprimé")
END
IF NOT EmailReadNext(NumSession, "NON LUS") THEN
Error("Erreur lors de la lecture du message suivant")
END
END
Step 4: Ending the email session Once the management of incoming and outgoing emails is completed, the session is closed with EmailCloseSession. This function must be the last "email" function used. Example: The following code is a procedure for closing an e-mail session. In this code, the SessionNum variable corresponds to the session identifier returned by EmailStartSession. PRODEDURE FermetureSession(NumSession)
EmailCloseSession(NumSession)
This page is also available for…
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|