ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

This content has been translated automatically.  Click here  to view the French version.
Help / WLanguage / WLanguage functions / Communication / Managing emails
  • Principle
  • Read an email (variable of type Email): The different stages
  • Example
  • Reading an Email (Email structure): The different stages
  • Example
WINDEV
WindowsLinuxJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac Catalyst
Others
Stored procedures
Principle
This help page explains how to read an email from a WINDEV application and how to display its content in a WINDEV application.
The email is read by several WLanguage functions (EmailReadFirst, EmailReadNext, ...).
The content of the email can be retrieved:
  • in a variable of type Email. The Email variables allow you to handle several emails simultaneously.
  • via the Email structure. The variables of this structure contain the informations regarding the email read.
The variables of Email structure (as well as the properties of Email variables) correspond to the email characteristics.
Read an email (variable of type Email): The different stages
The steps for reading an email in WLanguage are as follows:
  1. Use a function for reading emails to browse all the emails of a messaging session, several syntaxes are available:
    • Perform a loop such as:
      MaSession is emailPOP3Session
      MonMessage is Email
      EmailReadFirst(MaSession, MonMessage)
      WHILE NOT MonMessage.Out
      	// Insérer ici le traitement du message
      	EmailReadNext(MaSession, MonMessage)
      END
    • Retrieve all the messages in an array with EmailGetAll:
      MaSession is emailPOP3Session
      MesMessages is array of Email = EmailGetAll(MaSession)

      Remarks:
      • When using the POP3 protocol, the incoming emails that can be read are the emails that have been received when the session was started. All the emails received once the session is started are not "visible". To access the new incoming emails, the session must be closed and re-started.
      • To follow the reading progress, use EmailProgressBar.
  2. Read the content of the Email variable.
    Note: If the Email contains specific headers, they can be read using the Email type variable.
  3. If the HTML property is not empty: message is in HTML format. It must be displayed in a browser (see the example below).
    For each attached file:
    • Save the file on disk (EmailSaveAttachment).
    • Browse the HTML message and find the "cID:"+Identifier value of the attached file. Replace this value by the full path of attached file copied on disk.
      Display the message in a browser.
  4. If the HTML property is empty: the message is in text format.
  5. Save the attached files on disk if necessary and display the message text.

Example

MonMessage is Email 
...
Repert_Temp is string = "C:\temp\"
CID is string
I is int
// Pour chaque fichier attaché
Attachement is emailAttach
FOR EACH Attachement OF MonMessage.Attach
	// Copier le fichier dans un répertoire temporaire 
	EmailSaveAttachment(Attachement, Repert_Temp + Attachement.Name)
	// Récupérer l'identifiant du fichier attaché dans le mail
	CID = "cid:" + Attachement.Identifier
	// Remplacer les références au fichier attaché par le nom réel du fichier
	MonMessage.HTML = Replace(MonMessage.HTML, CID, ...
			"file:" + Repert_Temp + Attachement.Name)
END
// Afficher le contenu HTML dans un champ HTML
HTM_Affichage = MonMessage.HTML
Reading an Email (Email structure): The different stages
The steps for reading an email in WLanguage are as follows:
  1. Use a function for reading emails (EmailReadFirst, EmailReadNext, ...). To follow the reading progress, use EmailProgressBar.
  2. Read the content of the email structure (see the example below).
  3. If variable Email.HTML is not empty: message is in HTML format. It must be displayed in a browser.
    For each attached file (the Email.NbAttach variable is not empty):
    • Save the file on disk (EmailSaveAttachment).
    • Browse the HTML message and find the "cID:"+Email.AttachIdentifier value of the attached file. Replace this value by the full path of attached file copied on disk.
    • Display the message in a browser.
  4. If the Email.HTML variable is empty: the message is in text format.
  5. Save the attached files on disk if necessary and display the message text.
Note When using the POP3 protocol, the emails received that can be read are those received at the time the session is opened. All the emails received once the session is started are not "visible". To access the new incoming emails, the session must be closed and re-started.

Example

Repert_Temp is string = "C:\temp\"
CID is string
I is int

// Pour chaque fichier attaché
FOR I = 1 TO Email.NbAttach
	// Copier le fichier dans un répertoire temporaire 
	EmailSaveAttachment(Email.Attach[I], ...
			Repert_Temp + Email.Attach[I])
	// Récupérer l'identifiant du fichier attaché dans le mail
	CID = "cid:" + Email.AttachIdentifier[I]
	// Remplacer les références au fichier attaché 
	// par le nom réel du fichier
	Email.HTML = Replace(Email.HTML, CID, "file:" + ...
			Repert_Temp + Email.Attach[I])
END

// Afficher le contenu HTML dans un Browser WEB
// Créer un fichier temporaire contenant le HTML
NomFic is string = Repert_Temp + "temp.htm"
hFic is int = fOpen(NomFic, foCreate + foWrite)
fWrite(hFic, Email.HTML, Length(Email.HTML))
fClose(hFic)

// Fournir le fichier HTML temporaire au browser
// navigateur_WEB est un champ ActiveX "Microsoft Web Browser"
navigateur_WEB>>Navigate(NomFic)
Related Examples:
WD Mail Complete examples (WINDEV): WD Mail
[ + ] This application is an email client developed in WINDEV. It is based on the Email objects.
This email client is used to retrieve and send emails by using the POP, IMAP and SMTP protocols.
You have the ability to apply filters to the incoming emails.

The application can also be used to manage several email accounts. The writing of an email is based on the HTML edit control.
The POP3 Email functions Unit examples (WINDEV): The POP3 Email functions
[ + ] Using the Email functions to manage the POP3 protocol.
This protocol is used to retrieve emails from a server.
WD JavaMail Training (WINDEV): WD JavaMail
[ + ] This example is a Java example used to read and send emails.
Minimum version required
  • Version 9
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 03/27/2025

Send a report | Local help