PC SOFT

WINDEVWEBDEV AND WINDEV MOBILE
ONLINE HELP

Home | Sign in | English UK
This content comes from an automatic translation.
  • This lesson will teach you the following concepts
  • NOTE2_1
  • NOTE3_1
  • Validate the proposed information.
  • The "Password" edit control appears in the editor with a bullet and an eye.
  • Creating an edit control
  • END
  • WLanguage code for preparing the email:
  • MyMessage..Message
  • //############
Lesson 4.9. Sending an email
This lesson will teach you the following concepts
  • How to send an email from a WINDEV application.
  • How to include a supercontrol in a window.
  • How to define the tab order in a window.
  • How to open a non-modal window.

Lesson duration: Estimated time
Previous LessonTable of contentsNext Lesson
NOTE2_1
Overview. Several WLanguage functions allow you to manage the incoming and outgoing emails
  • You also have the ability to access the email characteristics:
  • sender, recipients,
  • outgoing date, subject, message,
attachments...
  • WINDEV proposes several methods for managing emails:
    • Management via Lotus Notes, Outloook or MS Exchange:: The Lotus Notes or Outlook messaging software
    • these programs allow you to send and receive emails.: The "Simple Mail API" (also called SMAPI or Simple MAPI)
  • this management mode of emails is used by most of the Microsoft applications, especially by Microsoft Exchange.
    • Management via the POP3, IMAP and SMTP protocols:: The POP3 protocol. this protocol for receiving emails is recognized by all service providers. It is used to communicate with the server directly, available at your ISP
    • This protocol is used to list the incoming messages and to read them.: The IMAP protocol
    • this protocol for receiving emails is used to leave the emails the server so that they can be consulted from different messaging clients or webmails.: The SMTP protocol.
this protocol for sending emails is recognized by all service providers. In this lesson, we are going to create a window allowing the user to send an email from the "WD Full Application" application: This window is as follows
Window for sending an email. We are going to use the SMTP protocol.
Indeed, this mode is commonly used all over the world
See the online help for more details about the other methods.

For more details on the other methods

Communicating by emails
To follow this lesson, you must have followed the lessons of this part until .: "Lesson 4.7. Printing a list of customers"
A full corrected application project is also available

in WINDEV's home page (Ctrl + <)

Example. See the "WD Mail" example (full example supplied with WINDEV) for more details
NOTE3_1
A window for sending emails. This window will contain all controls allowing the user to type the different email elements

  • NOTE3_2
    1. Creating the window
    2. Create a new window:
      • Open the "WD Full Application" project if necessary.
      • Click among the quick access buttons.: Create an element
      • The element creation window appears
      • click "Window" then "Window".: The window creation wizard starts.
    3. In the "Based on a template" tab pane, select "Use. WINTPL_Template" and validate the wizard.. The window for saving an element is displayed

Validate the proposed information.

NOTE3_3. Creating the controls used to configure the sending
  • In a first time, we are going to create all controls for configuring the SMTP server used to send messages
  • Four edit controls are required:
  • SMTP server,
  • Port of SMTP server,
  • User name,
    1. User password.
    2. To create the edit control corresponding to the name of SMTP server:
    3. On the "" pane, in the "" group, click .: Creation
    4. Usual controls. Creating an edit control. The control shape appears under the cursor.. Click the top left corner of window.
  • the edit control is automatically created.
    1. Select the control and press Enter
    2. The caption becomes editable
    3. Type "SMTP server" and validate
    4. The control name automatically corresponds to EDT_SMTP_Server: To create the edit control corresponding to the port:
    5. On the "" pane, in the "" group, expand "Edit".. Creation. Usual controls. Select a preset Integer edit control..
  • The control shape appears under the cursor.
    1. Click below the "SMTP server" control
    2. the edit control is automatically created.
    3. Select the control and press Enter: The caption becomes editable
    4. Type "Port" and validate. The control name automatically corresponds to EDT_Port. To create the edit control corresponding to the user name:. On the "" pane, in the "" group, click ..
  • Creation
    1. Usual controls
    2. Creating an edit control
    3. The control shape appears under the cursor.
    4. Click below the "Port" control: the edit control is automatically created..
      Select the control and press Enter

      The caption becomes editable

      Type "User" and validate
      The control name automatically corresponds to EDT_User. To create the edit control corresponding to the user password:: On the "" pane, in the "" group, expand "".
      Creation. Usual controls
  • Edit
    1. Select a preset "Password" edit control.
    2. The control shape appears under the cursor.. Click below the "User" control
    3. the edit control is automatically created

The "Password" edit control appears in the editor with a bullet and an eye.

At runtime, when the user enters their password, the characters will be replaced by bullets
  • A click on the eye will allow the user to see his password in clear
  • this allows the user to check his password.
  • This feature can be disabled by programming if necessary
  • See the online help for more details.. This feature can be disabled by programming if necessary
  • See for more details.
Showing the password
  • Align the created controls:
    1. Select the four controls.
    2. On the "" pane, in the "" group, click ""
    3. Alignment: Inside and outside
    4. Justify (Ins. and Out.). 'Alignment' pane
  • Interface of the window to create. Save the window ( or Ctrl + S).
    1. Save an element
    2. NOTE3_4
    3. Creating the controls used to type the email characteristics: To write an email, the user must have:
    4. A control used to type the sender address.. A control used to type or select the recipient address.
    5. A control used to type the email subject.. A control used to type the email text
    6. The user must have the ability to format the email text.
      • A control used to add attachments.
      • We are now going to create these controls in our window.
      To create the edit control corresponding to the sender address:
    7. On the "" pane, in the "" group, expand "".. Creation
    8. Usual controls. Edit
    9. Enter "Email" in the search box at the top of the list of preset controls. Select "eMail edit".
    10. The control shape appears under the cursor.. Click below the "Password" control. the edit control is automatically created.
    11. Select the control and press Enter
      • The caption becomes editable
      • Type "Sender" and validate.
    12. The control used to type the recipient address must list the addresses of the customers found in the database but it must also allow the user to type another address. To do so, we will use an "Editable combo box" control linked to the Customer data file.
  • On the "" pane, in the "" group, click "".
    1. Creation
    2. Usual controls
    3. Combo Box: The control shape appears under the cursor.
    4. Click below the "Sender" control. the Combo Box control creation wizard starts automatically.. Select "Display the data found in a file or in an existing query"
  • Go to the next step.: Select the Customer data file
    1. Go to the next step.
    2. The email addresses of customers must be displayed in the control:
    3. Uncheck the "CustomerID" item.
    4. Check the "Email" item.: Go to the next step.
    5. The sort item is the "Email" item
    6. Go to the next step.
      • The return value is the "Email" item. Go to the next step.
      • Keep the default options
    7. Go to the next step.
  • In the "Additional parameters" screen, check "Allow input". Indeed, the user must have the ability to type a new email address. Go to the next step..
    1. Modify the name and caption of Combo Box control:. The control name is "COMBO_Recipient".
    2. The control caption becomes "Recipient".: Validate the wizard. The control is automatically created in the window..
  • To create the edit control corresponding to the email subject:. On the "" pane, in the "" group, click .
Creation

Creating an edit control

  • The control shape appears under the cursor.
    1. Click below the "Recipient" control
    2. the edit control is automatically created.
    3. Select the control and press Enter. The caption becomes editable
    4. Type "Subject" and validate.: For the message body, we will use an HTML Edit control
    5. the user will have the ability to format the email text via a specific toolbar.
      • On the "" pane, in the "" group, expand "".
        Creation
        Usual controls
        Edit
        Enter "HTML" IN the search box at the top of the list of preset controls
        Select "HTML edit".
        The control shape appears under the cursor.
        Click below the "Subject" control
        the edit control is automatically created., ...
        Enlarge the control IN order FOR several lines TO be Visible.
        Open the control description window (double-click the control).
        ON the "General" TAB, modify the mode FOR displaying the formatting toolbar
        This toolbar must always be visible.. Validate the control description window.. Reposition the control if necessary in order for the toolbar to be displayed properly.
      • Via the popup menu of control ("Browse" option), the user will be able to select the file to attach
        ON the "" pane, IN the "", expand ""
         
        The list of preset controls proposed by Default is displayed.
        Creation
        Usual controls
        Edit
         
        Select the "File" control AND perform À Drag AND Drop toward the "WIN_Sending_an_email" window
        drop the control below the "HTML text" control,...
        The file picker is immediately created
         
        Align the different controls found IN the window
         
        Window FOR writing emails
        We will Now create the Button control TO send emails.
        NOTE3_5. Sending the email.
      • On the "" pane, in the "" group, click .
        // Send the email
        IF EmailSendMessage(MySession, MyMessage) = False THEN
        Error("Message not sent.", ErrorInfo())
        ELSE
        // Message sent
        ToastDisplay("Message sent", toastShort, ...
        vaMiddle, haCenter)
        END
        Write the following lines of code in the "Click" event:. WLanguage code for opening the connection and starting the SMTP session:.
        //############. MySession is emailSMTPSession
      • MySession..Password = EDT_Password
        // Closes the SMTP session
        EmailCloseSession(MySession)
        // Starts the SMTP session
  • Error("Unable to connect to the SMTP server."
END
This code uses an advanced variable
  • The different properties of this variable are used to define the characteristics of SMTP session
  • Then, associated with this variable is used to start the session.
  • emailSMTPSession

WLanguage code for preparing the email:

  • COMBO_Recipient is a
    1. //############: MyMessage is Email
    2. MyMessage..Sender = EDT_Sender
    3. MyMessage..Subject = EDT_Subject

MyMessage..Message

  • // Adds a recipient
    • Add(MyMessage..Recipient: COMBO_Recipient..DisplayedValue)
    • // Adds the attachment if necessary: IF EDT_File <> "" THEN
    • EmailLoadAttachment(MyMessage, EDT_File): END
    • This code uses an variable: The different properties of this variable are used to define the characteristics of email to send
  • This code associates the content of different window controls to the properties of Email variable.
    Email

    WLanguage code for sending the email:

    //############. // Send the email. IF EmailSendMessage(MySession, MyMessage) = False THEN. Error("Message not sent.", ErrorInfo())
    • ELSE: // Message sent
    • ToastDisplay("Message sent", toastShort
    1. vaMiddle, haCenter)
    2. END: The email is sent by
    3. Simply pass as parameters: the variable that contains the characteristics of the SMTP session, and the variable that contains the characteristics of the email to send. If the email is sent, a Toast message is displayed, indicating that the email was sent
    4. A Toast message corresponds to a furtive message.
    5. EmailSendMessage

//############

// Closes the SMTP session. EmailCloseSession(MySession)
  • This code closes the session with .
    1. EmailCloseSession
    2. Save the window and its code ( or Ctrl + S).
    3. Save the element
    4. NOTE4
    5. NOTE4_1
    6. Window improvements
    7. We are going to improve our window:
    8. Add a Button control to close the window.
      // Opens the window for sending emails
      OpenChild(WIN_Sending_an_email)
      : NOTE4_2
  • To add a Button control to close the window:
  • On the "" pane, in the "", expand "". the list of preset buttons is displayed.
Previous LessonTable of contentsNext Lesson
Minimum version required
  • Version 24
Comments
Click [Add] to post a comment