This content has been translated automatically.  Click here  to view the French version.
Help / WLanguage / WLanguage functions / Communication / Managing emails
  • Properties specific to emailSMTPSession variables
  • Functions that use emailSMTPSession variables
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WindowsLinuxPHPWEBDEV - Browser code
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac CatalystUniversal Windows 10 App
Stored procedures
The emailSMTPSession type is used to access a messaging server by using the SMTP protocol (Simple Mail Transfer Protocol) in order to send emails. The characteristics of the connection can be defined and changed using different WLanguage properties.
  • For more details on the declaration of this type of variable and the use of WLanguage properties, see Declaring a variable.
  • In most cases, the SMTP server to use is the SMTP server of Internet provider (and not the one of email account). For example, if you have Internet access via Orange and a Free email account, you must use the SMTP server of Orange (and not the one of Free). To use a different SMTP server, you must use an authenticated SMTP server, that requires a secure connection in most cases.
WINDEVWEBDEV - Server code
// Connexion avec authentification
// Session SMTP sécurisée TLS
MaSessionSMTP is emailSMTPSession
OAuthCnxGoogle is OAuth2Parameters
// Paramètres de connexion OAuth
OAuthCnxGoogle.ClientID = "ID de l'application"
OAuthCnxGoogle.ClientSecret = "ID secret de l'application"
OAuthCnxGoogle.AuthURL = ""
OAuthCnxGoogle.TokenURL = ""
OAuthCnxGoogle.Scope = ""
OAuthCnxGoogle.RedirectionURL = "http://localhost:9000"
OAuthCnxGoogle.ResponseType = oauth2ResponseTypeCode
// Identification OAuth
MaSessionSMTP.ServerAddress = ""
MaSessionSMTP.Name = ""
MaSessionSMTP.Password = "secret"
MaSessionSMTP.Port = 587
MaSessionSMTP.Option = emailProtocolSMTPS
MaSessionSMTP.AuthToken = AuthIdentify(OAuthCnxGoogle)
// Si l'identification a réussi, il faut se connecter à la boîte email
IF MaSessionSMTP.AuthToken <> Null THEN
IF EmailStartSession(MaSessionSMTP) = False THEN
// Erreur d'ouverture de session
Error("Impossible d'ouvrir la session SMTP.", ErrorInfo(), ...
"En cas de TimeOut, assurez-vous des paramètres du " + ...
"""Pare-Feu"" sur le port utilisé (" + MaSessionSMTP.Port + ")")
// Envoi d'un message
MonEmail is Email
EmailSendMessage(MaSessionSMTP, MonEmail)
// Erreur d'authentification

Properties specific to emailSMTPSession variables

The following properties can be used to handle emailSMTPSession variables:
Property nameType used Effect
AsynchronousBoolean or Integer constant
  • emailAsynchronous (or True) if the emails sent during the session started by EmailStartSMTPSession must be transmitted in asynchronous mode.
  • emailSynchronous (or False) otherwise (default value).
WINDEVLinuxUniversal Windows 10 AppAndroidAndroid Widget iPhone/iPad This property is not available: the send operation is always performed in synchronous mode.
AuthTokenAuthToken variableEmail server access token to be used when if the OAuth 2.0 protocol is used (two-factor authentication). This access token is retrieved by AuthIdentify.
LinuxUniversal Windows 10 AppAndroidAndroid Widget This property is not available.
nomCharacter stringUsername to be used for authenticated SMTP sessions.
OptionInteger constantOptions of SMTP connection. The possible values are:
  • emailOptionDefault (default value):
    Start a non-secure SMTP session. In this case, the standard port is port 25.
  • emailProtocolSMTPS:
    Start an SMTP session secured by the TLS protocol. In this mode:
    • the initial connection is established unencrypted, then a STARTTLS command is sent to begin encryption,
    • the standard port is 587.
  • optionTLS:
    Start an SMTP session secured by the TLS protocol. In this case, the standard port is port 465.
Universal Windows 10 App This property is not supported.
PasswordCharacter stringUser password. This password is given by the service provider or by the network administrator. This password is used to start an authenticated SMTP session.
PortentierIdentifies the port used for the SMTP protocol (25 by default).
ServerAddressCharacter stringDNS name or IP address of email server (outgoing protocol). This address is supplied by the service provider or by the network administrator.
Caution: You must use the SMTP server of the provider of Internet connection. This SMTP server may have no link with the SMTP server associated with the email account.

Remark: Changing the names of constants (version 28 Update 4):
As of version 28 Update 4, the names of constants have been changed to improve code readability.. Constant names correspond as follows:
  • the emailOptionSécuriséTLS constant has become emailProtocolSMTPS.
  • the optionSSL constant has become optionTLS.
Old constant names:
  • are no longer colored in the code editor,
  • are no longer offered by the code editor completion,
  • can still be used without causing a compilation error or a change in runtime behavior.

Functions that use emailSMTPSession variables

EmailCloseSessionCloses an email management session depending on the selected mode (SMTP/POP3, IMAP, MS Exchange or Lotus Notes).
EmailSendMessageSends an email using a given protocol (SMTP, MS Exchange, Lotus Notes, Outlook).
EmailStartSessionStarts an email management session based on the selected management mode (POP3, SMTP, IMAP or MS Exchange).
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.
Minimum version required
  • Version 15
This page is also available for…
Click [Add] to post a comment

Last update: 06/29/2023

Send a report | Local help