AYUDA EN LÍNEA
 WINDEVWEBDEV Y WINDEV MOBILE

Este contenido se ha traducido automáticamente.  Haga clic aquí  para ver la versión en inglés.
Ayuda / WLanguage / Funciones WLanguage / Comunicación / Gestión de correos electrónicos
  • 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
WINDEV
WindowsLinuxJavaReportes y ConsultasCódigo de Usuario (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Código Navegador
WINDEV Mobile
AndroidWidget Android iPhone/iPadIOS WidgetApple WatchMac Catalyst
Otros
Procedimientos almacenados
Overview of "Simple MAPI"
Simple MAPI simplifies management of e-mail received at the hosting provider. 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".
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 for example).
  2. From the WINDEV application (or from the WEBDEV website), 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 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:
  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

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 Procedure for opening an e-mail 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 could not be opened. Error: " + Email.Error)
END
RETURN 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 synchronizes the e-mail server and the e-mail management application: new e-mails received are automatically transferred to the 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 is used to send all emails present in a table control 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_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 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 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.
// 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

// Loop through unread messages and display them in a Table control populated programmatically
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: 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 CloseSession(SessionNum)
// Close the session
EmailCloseSession(SessionNum)
Versión mínima requerida
  • Versión 9
Esta página también está disponible para…
Comentarios
Haga clic en [Agregar] para publicar un comentario

Última modificación: 27/03/2025

Señalar un error o enviar una sugerencia | Ayuda local