PC SOFT

ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Home | Sign in | English EN
This content has been translated automatically. Click here to view the French version.
  • Principle
  • Reading an email (Email variable): The different steps
  • Example
  • Reading an email (Email structure): The different steps
  • Example
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac CatalystUniversal Windows 10 App
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:
  • Versions 15 and later
    in an variable of type Email. The Email variables allow you to handle several emails simultaneously.
    New in version 15
    in an variable of type Email. The Email variables allow you to handle several emails simultaneously.
    in an 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.
Versions 17 and later
iPhone/iPad This feature is now available for iPhone/iPad applications.
New in version 17
iPhone/iPad This feature is now available for iPhone/iPad applications.
iPhone/iPad This feature is now available for iPhone/iPad applications.
Versions 21 and later
Universal Windows 10 App This feature is now available in Universal Windows 10 App mode.
New in version 21
Universal Windows 10 App This feature is now available in Universal Windows 10 App mode.
Universal Windows 10 App This feature is now available in Universal Windows 10 App mode.
Versions 22 and later
Android Widget This feature is now available in Android Widget mode.
Android This feature is now available for Android applications.
New in version 22
Android Widget This feature is now available in Android Widget mode.
Android This feature is now available for Android applications.
Android Widget This feature is now available in Android Widget mode.
Android This feature is now available for Android applications.
Reading an email (Email variable): The different steps
The steps for reading an email in WLangage 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 contents of the Variable type Email.
    Versions 19 and later
    Remark: If the email contains specific headers, they can be read via the Email variable.
    New in version 19
    Remark: If the email contains specific headers, they can be read via the Email variable.
    Remark: If the email contains specific headers, they can be read via the Email variable.
  3. If the Property HTML is not empty: the 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 Property HTML 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 steps
The steps for reading an email in WLangage 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 the Email.HTML variable is not empty: the 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.
Remark: 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.

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