ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

This content has been translated automatically.  Click here  to view the French version.
Help / WLanguage / WLanguage functions / Communication / Managing emails
  • SMTP protocol
  • Session and username
  • Authenticated SMTP
  • Timeout
  • Managing emails in asynchronous mode
  • Gmail: What to do if a connection to Gmail (SMTP, IMAP, POP3) fails with a certificate error?
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
Starts a session for sending emails with the SMTP protocol. You will only have the ability to send emails.
Remarks:
  • 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 start a session for receiving and reading emails, use EmailStartPOP3Session.
  • You also have the ability to use an emailSMTPSession variable.
Example
// Envoi d'un email par un serveur SMTP non sécurisé
EmailSetTimeOut(10) // 10 secondes pour le time out
// Attention: il faut utiliser le serveur SMTP du fournisseur d'accès Internet
let sServeursSMTP = "smtp.orange.fr"
IF EmailStartSMTPSession(sNomUser, sMotDePasse, sServeurSMTP) = True THEN
// Procédure permettant d'initialiser la structure email
Initialise_Email()
// Envoie l'email
IF EmailSendMessage(sNomUser) = False THEN
Error()
END
EmailCloseSession(sNomUser)
ELSE
Error("Impossible d'établir la connexion", ErrorInfo(), ...
"En cas de Time Out, assurez-vous des paramètres du " + ...
"""Pare-Feu"" sur le port utilisé (25)")
END
WEBDEV - Server codeWindowsAjax
NomUser is string
 
NomUser = "monadresse@gmail.com"
// Envoi d'un email par le protocole SMTP sécurisé
EmailSetTimeOut(10) // 10 secondes pour le time out
// Utilisation d'un serveur SMTP sécurisé avec authentification
// Nécessaire en général pour utiliser un SMTP
// différent de celui du fournisseur d'accès Internet
IF EmailStartSMTPSession(NomUser, "MotDePasse", ...
"smtp.gmail.com", 587, False, emailProtocolSMTPS) = True THEN
// Procédure permettant d'initialiser la structure email
Initialise_Email()
// Envoie l'email
IF EmailSendMessage(NomUser) = False THEN
Error()
END
EmailCloseSession(NomUser)
ELSE
Error("Impossible d'établir la connexion", ErrorInfo(), ...
"En cas de Time Out, assurez-vous des paramètres du "+ ...
"""Pare-Feu"" sur le port utilisé (587)")
END
Syntax
<Result> = EmailStartSMTPSession(<Username> [, <Password>] , <Address of SMTP server> [, <Number of SMTP port> [, <Asynchronous mode> [, <Option>]]])
<Result>: Boolean
  • True if the session was started,
  • False otherwise. If an error occurs, the ErrorOccurred variable is set to True.
    To get more details on the error, use ErrorInfo with the errMessage constant.
<Username>: Character string
Identifies the email session in the functions for email management (used by EmailSendMessage to send emails for example).
<Password>: Optional character string
User password. This password is given by the service provider or by the network administrator. This password is used to start an authenticated SMTP session.
<Address of SMTP server>: Character string
DNS name or IP address of email server (outgoing protocol). This IP 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.
<Number of SMTP port>: Optional integer
Identifies the port used for the SMTP protocol (25 by default).
<Asynchronous mode>: Optional constant or boolean
emailAsynchronous (or True)The emails sent during the session started by EmailStartSMTPSession must be transmitted in asynchronous mode.
emailSynchronous (or False)
(default value)
The emails sent during the session started by EmailStartSMTPSession must be transmitted in synchronous mode.

<Option>: Optional Integer constant
Options of SMTP session. The possible values are:
emailOptionDefault
(default value)
Start the SMTP session.
emailProtocolSMTPSStart the SMTP session secured by the TLS protocol.
As of version 28 Update 4, the name of this constant has been changed to improve the readability of the code.. In previous versions, this constant was named emailOptionSécuriséTLS.
optionTLSStart the SMTP session secured by the SSL protocol. This type of session is used by the Orange, Free and Gmail servers for example.
As of version 28 Update 4, the name of this constant has been changed to improve the readability of the code.. In previous versions, this constant was named optionSSL.

Remarks

SMTP protocol

  • The different parameters passed to EmailStartSMTPSession are supplied by the Internet Service Provider or by the network administrator. An Internet connection is required to manage the emails. Several cases may occur:
    • The user uses a modem to connect to Internet: NetOpenRemoteAccess establishes the Internet connection.
    • The user uses a direct connection to Internet (cable or ADSL): no specific operation is required.
  • The SMTP protocol can only be used to send emails. A WLanguage error occurs if you try to read emails without starting a POP3 session (EmailStartPOP3Session). To start a POP3 session and an SMTP session at the same time, use EmailStartSession.

Session and username

After starting an SMTP session, you can start a POP3 session (EmailStartPOP3Session) with the same username.

Authenticated SMTP

<Password> is used to start an authenticated SMTP session. The supported authentication mechanisms are SMTP Login and Plain.
If the server recognizes one of these two authentication mechanisms and if the authentication fails, the connection fails as well.
If the server does not recognize one of these two authentication mechanisms and if the authentication fails, EmailStartSMTPSession tries to connect without authentication.
Remark: the SMTP authentication cannot be performed by EmailStartSession. To start a POP3 session and an authenticated SMTP session at the same time, you must use both EmailStartPOP3Session and EmailStartSMTPSession.

Timeout

The timeout can be set using EmailSetTimeOut.
WEBDEV - Server codeAjax

Managing emails in asynchronous mode

The email functions are locking functions by default. Which means that no other code can be run during their execution. The program will resume only when the current Email functions have been run.
WEBDEV gives you the ability to manage the emails in asynchronous mode. This mode allows your sites to send emails without locking the execution of other processes.
To use the asynchronous mode, you must:
  1. Uncheck "Disable the email spooler" in the WEBDEV administrator ("Advanced" tab).
  2. Enable the asynchronous mode when starting the SMTP session (with EmailStartSMTPSession or EmailStartSession).
  3. All outgoing emails will be transmitted to a "spooler". Emails are queued up before being sent.
Executing Email functions does no longer block the rest of the program. EmailStatus is used to determine the status of an email.
Remark: If the WEBDEV administrator is closed, the email spooler is cleared: pending emails are not sent and are removed from the spooler.
If there are pending emails, and the "Disable the email spooler" option is checked, the emails will not be lost: the administrator continues to send them, but the spooler will not accept any new emails.
Caution: The asynchronous mode can only be used when starting a session on an SMTP server (EmailStartSMTPSession for sending emails or EmailStartSession). The asynchronous mode is ignored in all other cases.

Gmail: What to do if a connection to Gmail (SMTP, IMAP, POP3) fails with a certificate error?

Since August 2017, a new certificate was deployed by Google: Google Internet Authority G3. Unfortunately, the Windows API for checking certificates does not validate this certificate.
Therefore, starting a POP3, IMAP or SMTP session may fail with the error "The certificate string was not issued by a trusted authority".
To validate the certificate, all you have to do is modify the management mode of emails. The WLanguage EmailConfigure function allows you to change this mode and to no longer use the Windows API that locks this certificate. The following code must be added before starting the session via EmailStartSMTPSession:
// Activation de l'implémentation multiplateforme
EmailConfigure(emailParameterMode, 1)
Remark: From version 23 Update 1, the call to EmailConfigure is not required anymore: WLanguage is automatically using the management mode of emails adapted to the session.
Business / UI classification: Business Logic
Component: wd290com.dll
Minimum version required
  • Version 9
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 06/29/2023

Send a report | Local help