PC SOFT

ONLINE HELP
FOR WINDEV, WEBDEV AND WINDEV MOBILE

Home | Sign in | English US
  • 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/iPadApple WatchUniversal Windows 10 AppWindows Mobile
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 Email variable. The Email variables allow you to handle several emails simultaneously.
    New in version 15
    in an Email variable. The Email variables allow you to handle several emails simultaneously.
    in an Email variable. 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 characteristics of an email.
Versions 17 and later
iPhone/iPad This feature is now available for the iPhone/iPad applications.
New in version 17
iPhone/iPad This feature is now available for the iPhone/iPad applications.
iPhone/iPad This feature is now available for the 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 the Android applications.
New in version 22
Android Widget This feature is now available in Android Widget mode.
Android This feature is now available for the Android applications.
Android Widget This feature is now available in Android Widget mode.
Android This feature is now available for the 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:
      MySession is EmailPOP3Session
      MyMessage is Email
      EmailReadFirst(MySession, MyMessage)
      WHILE NOT MyMessage..Out

      // Insert the message process

      EmailReadNext(MySession, MyMessage)
      END
    • Retrieve all the messages in an array with EmailGetAll:
      MySession is EmailPOP3Session
      MyMessages is array of Email = EmailGetAll(MySession)

      Notes:
      • 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 progress of reading, use EmailProgressBar.
  2. Read the content of Email variable.
    Versions 19 and later
    Note: If the email contains specific headers, they can be read via the Email variable.
    New in version 19
    Note: If the email contains specific headers, they can be read via the Email variable.
    Note: If the email contains specific headers, they can be read via the Email variable.
  3. If ..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 ..HTML is empty: the message is in text format.
  5. Save the attached files on disk if necessary and display the message text.

Example

MyMessage is Email
...
Temp_Dir is string = "C:\temp\"
CID is string
I is int

// For each attached file
Attachment is EmailAttach
FOR EACH Attachment OF MyMessage..Attach
// Copy the file into a temporary directory
EmailSaveAttachment(Attachment,Temp_Dir + Attachment..Name)
// Retrieve the identifier of the attached file
CID ="cid:" + Attachment..Identifier
// Replace the references to the attached file
// by the real name of the file
MyMessage.HTML = Replace(MyMessage.HTML, CID, ...
"file:" + Temp_Dir + Attachment..Name)
END

// Display the HTML content in an HTML control
HTM_Display = MyMessage..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 progress of the read operation, 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.
Note: 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

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

// For each attached file
FOR I = 1 TO Email.NbAttach
// Copy the file into a temporary directory
EmailSaveAttachment(Email.Attach[I], ...
Temp_Dir + Email.Attach[I])
// Retrieve the identifier of the attached file
CID = "cid:" + Email.AttachIdentifier[I]
// Replace the references to the attached file
// by the real name of the file
Email.HTML = Replace(Email.HTML, CID, "file:" + ...
Temp_Dir + Email.Attach[I])
END

// Display the HTML content in a Web browser
// Create a temporary file containing the HTML
FileName is string = Temp_Dir + "temp.htm"
hFile is int = fOpen(FileName, foCreate + foWrite)
fWrite(hFile, Email.HTML, Size(Email.HTML))
fClose(hFile)

// Supply the temporary file to the browser
// Web_Browser is an ActiveX control "Microsoft Web Browser"
Web_browser>>Navigate(FileName)
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 create an applet.
This applet can then be used in an Internet page.
This applet enables you read and send emails.
In this project, a second configuration enables you to manage a "Standard" Java application (.jar).
To generate the Java applet and the "Standard" Java application, select "Workshop - Java - Generate the Java archive",
for each one of the two configurations of project.
Minimum required version
  • Version 9
This page is also available for…
Comments
Click [Add] to post a comment