PC SOFT

ONLINE HELP
FOR WINDEV, WEBDEV AND WINDEV MOBILE

Home | Sign in | English US
  • Principle
  • The different steps
  • Writing an email with an Email variable
  • Writing an email with the Email structure
  • Examples
  • Example that is using EmailImportHTML
  • Example that is using the Email structure
  • Using the EML format to customize emails
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
Two methods can be used to manage the emails in WLanguage:
  • the Email structure that is used to easily handle a message.
    In this case, to write an email, you must use the different variables of Email structure.
  • Versions 15 and later
    the advanced Email type that proposes advanced features (databinding, serialization, multiple instances, etc.).
    In this case, to write an email, you must declare and initialize an Email variable. The possible attachments will be declared in the emailAttach variables and added to the ..Attach property of Email variable.
    New in version 15
    the advanced Email type that proposes advanced features (databinding, serialization, multiple instances, etc.).
    In this case, to write an email, you must declare and initialize an Email variable. The possible attachments will be declared in the emailAttach variables and added to the ..Attach property of Email variable.
    the advanced Email type that proposes advanced features (databinding, serialization, multiple instances, etc.).
    In this case, to write an email, you must declare and initialize an Email variable. The possible attachments will be declared in the emailAttach variables and added to the ..Attach property of Email variable.
When sending the message (EmailSendMessage), the data found in the email variable or structure will constitute the outgoing message.
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 This feature is now available for the Android applications.
This feature is now available in Android Widget mode.
New in version 22
Android This feature is now available for the Android applications.
This feature is now available in Android Widget mode.
Android This feature is now available for the Android applications.
This feature is now available in Android Widget mode.
The different steps

Writing an email with an Email variable

To write an email with an Email variable:
  1. Declare and initialize an Email variable by specifying the recipients, the subject, ... via ..Recipient, ..Cc, ..Cci and ..Subject. To follow the progress of conversation, fill the ..MessageID property as well.
  2. If the email is in text format:
    • Initialize ..Message with text of email.
    • Specify the attached files if necessary by declaring the emailAttach variable and by adding them to the ..Attach property of variable representing the email.
  3. If the email is in HTML format: Use EmailImportHTML to initialize the email properties. If the email contains images or multimedia files, they will be automatically added in attachment and the content of HTML email will be modified to support the attachments.
    Java EmailImportHTML is not available. You must use the method that is using the Email structure presented below.
  4. Versions 19 and later
    Specify additional headers if necessary via ..Header.
    New in version 19
    Specify additional headers if necessary via ..Header.
    Specify additional headers if necessary via ..Header.
  5. Send the email with EmailSendMessage. If the subject (or one of the email elements) contains special characters or accented characters, use the emailOptionEncodeHeader constant when the message is sent by EmailSendMessage. The email is sent to the server. The server stores the email until the session is closed. During this closing, the email is actually sent to the recipients.
WINDEVWindows Mobile Note: To follow the progress of email sending, use EmailProgressBar.

Writing an email with the Email structure

To write an email with the Email structure:
  1. Initialize the Email structure by specifying the recipients, the subject, ... (Email.Recipient, Email.NbRecipient, Email.NbCc, Email.Cc and Email.Subject). To follow the progress of conversion, fill Email.MessageID.
  2. If the email is in HTML format:
    • 1st case: EmailImportHTML is available:
      • Use EmailImportHTML to initialize the different variables of Email structure.
    • 2nd case: EmailImportHTML is not available:
      • Initialize the Email.Message and Email.HTML variables.
        Note: We recommend that you use a message in text format for the messaging systems that do not support the emails in HTML format.
      • Analyze the HTML message to detect all multimedia files included in the message.
      • For each multimedia file found:
        • Create an attached file. This attached file corresponds to the multimedia file (Email.Attach and Email.NbAttach variables).
        • Create an identifier (Email.AttachIdentifier). This identifier must have the following format "wdcid"+number of attached file. For example, WDCID5 if the corresponding file is the fifth attached file.
        • Search for the multimedia file in the HTML message and replace its name by the string: "cid:"+Email.AttachIdentifier.
          For example:
          Initial HTML code: <IMG src="C:\MyImages\Image.gif">
          Replaced HTML code: <IMG src="cid:WDCID5">
  3. Send the email with EmailSendMessage.
    Note: If the subject (or one of the email elements) contains special characters or accented characters, use the emailOptionEncodeHeader constant when the message is sent by EmailSendMessage.
PHP Example for PHP:
Email.Recipient = "address@email.comr"
Email.NbRecipient = 1
Email.Subject = "Email title"
Email.Message = "Email content"
EmailSendMessage()
Examples
WINDEVWEBDEV - Server codeWindowsLinuxWindows MobileUser code (UMC)

Example that is using EmailImportHTML

This example is used to send an email containing images:
// Start an SMTP session
MySession is emailSMTPSession
MySession..ServerAddress = "smtp.mycompany.com"
EmailStartSession(MySession)

// Build the message
MyMessage is Email
MyHTMLText = fLoadText("C:\Email\MyEmail.htm")

EmailImportHTML(MyMessage, MyHTMLText, "C:\Email")

MyMessage..Recipient = "bob@mycompany.net"
MyMessage..Subject = "Test"

// Send the message
EmailSendMessage(MySession, MyMessage, emailOptionEncodeHeader)

Example that is using the Email structure

This example is used to replace the references to the multimedia files (images, sounds, ...) found in the Email.HTML variable by their "CID" identifiers. This procedure is called for each file found.
PROCEDURE SetAttachFile(FileName, Subscript)
Email.Attach[Subscript] = FileName
Email.NbAttach ++

// Replace in Email.HTML all references to the attached files
// by the cid identifier
CID is string = "cid:wdcid" + Subscript

// The HTML file was not necessarily created in the current directory
// It can reference the attached files in any path
// Therefore, extract the file name without path

SimpleName is string = fExtractPath(FileName, fFileName + fExtension)

// Find the name of the file in Email.HTML
Pos is int = 0
StartPos, EndPos are int
SubString is string
Pos = Position(Email.HTML, SimpleName, Pos)
IF Pos <> 0 THEN
EndPos = Pos + Length(SimpleName)
// Find the start position of reference
// Find the " marker
Pos --
SubString = Email.HTML[[Pos]]
WHILE Pos > 1 AND SubString <> """"
   Pos --
   SubString = Email.HTML[[Pos]]
END
StartPos = Pos + 1
// Replace
SubString = Middle(Email.HTML, StartPos, EndPos - StartPos)
Email.HTML = Replace(Email.HTML, SubString, CID)
END
Using the EML format to customize emails
WINDEVWEBDEV - Server codeWindowsWindows MobileUser code (UMC) In some cases, the structure of outgoing emails may not correspond to the requested information.
Some examples:
  • The communication with some organizations (emails for SESAM-VITALE) may require specific structures.
  • You may also want to force a specific character set (for a non-Latin language).
  • You may want to specify a return address that differs from the sender address.
To customize these emails, WLanguage allows you to create the buffer of the email, to modify it and to send this email.
The following functions are used:
  • EmailImportSource: This functions is used to read an existing EML file and to automatically fill the variables of the Email structure.
  • EmailBuildSource: This function is used to generate the source code of an email. This function allows you to entirely define the source code of email by using the flexibility of Email structure.
  • EmailSend: This functions sends a "buffer" in EML format containing the structured email (created by EmailBuildSource for example).
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.
WD Mailshot Training (WINDEV): WD Mailshot
[ + ] This example explains how to send a mailshot with WINDEV.

This example is used to type the subject of the message, its content and its attachments.
Then, the user must select the customers to which the message will be sent.
The WLanguge EmailSendMessage() function is used to send the message to each selected customer.
Technical implementation:
An email server compatible with POP3/SMTP must necessarily be accessible from the computer on which the application is run.
Sending an email in HTML format Unit examples (WINDEV): Sending an email in HTML format
[ + ] Using the WLanguage "EmailImportHTML" function.
This function is used to import an HTML file into the email structure. This allows you to easily add images into the emails.
WW_CMS Complete examples (WEBDEV): WW_CMS
[ + ] This example is an example of CMS (Content Management System).
This is a site for content management, typically a site for displaying some articles.

This example is divided into 2 parts:
- An AWP part for the part that must be referenced
- A WEBDEV part for the management part

Note:
In order for some features of the example to operate (sending emails for example), the parameters must be modified in order to adapt them to your configuration.
These parameters are stored as constants defined in the code of the project.
Minimum required version
  • Version 9
This page is also available for…
Comments
Click [Add] to post a comment