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
  • Timeout
  • Connection with two-factor authentication
  • Gmail: What should I do if a connection to Gmail (SMTP, IMAP, POP3) fails due to a certificate error?
WINDEV
WindowsLinuxJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac Catalyst
Others
Stored procedures
Starts a session for receiving and reading emails with the IMAP protocol. You will only be able to read the emails. You have the ability to start a secure IMAP session via SSL.
Note To open an email session, use the EmailStartSMTPSession function.
Example
// Lecture d'un email par le protocole IMAP
IF EmailStartIMAPSession(SAI_USER, SAI_PASSWORD, "imap.mondomaine.fr") = True THEN
	TraiteEmailRecus()
ELSE
	Error("Impossible d'établir la connexion")
END
Syntax
<Result> = EmailStartIMAPSession(<Username> , <Password> , <Server address> [, <Port> [, <Option>]])
<Result>: Boolean
  • True if the session was started,
  • False otherwise. To get the details of the error, use ErrorInfo.
<Username>: Character string
Username on the server. This name is supplied by the service provider or by the network administrator. This name will be used to identify the email session in the different functions for email management.
<Password>: Character string or Secret string
User password. This password is given by the service provider or by the network administrator.
New in version 2025
Secret strings: If you use the secret string vault, the type of secret string used for this parameter must be "ANSI or Unicode string".
To learn more about secret strings and how to use the vault, see Secret string vault.
New in version 2025
AndroidAndroid Widget Secret strings are not available for this parameter in Android/Android widget applications.
<Server address>: Character string
Address of email server (incoming protocol). This address is supplied by the service provider or by the network administrator. This address can be specified as follows:
  • IP address in XXX.XXX.XXX.XXX format (192.168.1.1 for example).
  • IP address containing the server name (imap.mydomain.fr for example). This syntax is recommended.
  • IP address returned by NetIPAddress.
Note: The address must be an IPv4 address.
<Port>: Optional integer
Identifies the port used for the IMAP protocol (143 by default).
<Option>: Optional Integer constant
Used to specify whether an SSL connection is required:
emailOptionDefault
(Default value)
Non-secure connection.
optionTLSTLS connection required (for a secure IMAP server).
Note The port generally used for a secure IMAP server is 993 (not 143, the default port value).
Before version 28 Update 4, this constant was named optionSSL.
Remarks

Timeout

The timeout can be set using EmailSetTimeOut.

Connection with two-factor authentication

More and more providers offer secure email accounts (SMTP/IMAP) with two-factor authentication.
Here's how it works:
  • OAuth connection to the mailbox provider: this connection provides a token.
  • Use the token to connect to IMAP or SMTP email boxes.
Let's see an example of code that can be used:
// Exemple de connexion IMAP avec un compte Gmail
// et une double authentification
OAuthCnxGoogle is OAuth2Parameters
gMaSessionIMAP is emailIMAPSession

// Paramètres du serveur IMAP
gMaSessionIMAP.ServerAddress = "imap.gmail.com"
gMaSessionIMAP.Option = optionTLS
gMaSessionIMAP.Port = "993"

// Paramètres de connexion OAuth
OAuthCnxGoogle.ClientID = "ID de l'application"
OAuthCnxGoogle.ClientSecret = "ID secret de l’application"
OAuthCnxGoogle.AuthURL = "https://accounts.google.com/o/oauth2/auth"
OAuthCnxGoogle.TokenURL = "https://accounts.google.com/o/oauth2/token"
OAuthCnxGoogle.Scope = "https://mail.google.com/"
OAuthCnxGoogle.RedirectionURL = "http://localhost:9000"
OAuthCnxGoogle.ResponseType = "code"

// Identification OAuth
gMaSessionIMAP.AuthToken = AuthIdentify(OAuthCnxGoogle)
// Si l'identification a réussi, il faut se connecter à la boîte email.
IF gMaSessionIMAP.AuthToken <> Null THEN
	// utilisation de la syntaxe préfixée de la fonction EmailOuvreSession
	IF gMaSessionIMAP.StartSession() THEN
	// Session ouverte
	ELSE
	// Erreur d'ouverture de la session.
	END
ELSE
	// Erreur d'authentification.
END

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

Since the end of August 2017, Google has deployed a new certificate: 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 EmailStartIMAPSession:
// Activation de l'implémentation multiplateforme
EmailConfigure(emailParameterMode, 1)
Remarks:
  • As of version 23 Update 1, you no longer need to call the EmailConfigure function: WLanguage automatically uses the email management mode appropriate to the session.
  • You can handle certificate errors on an SMTP session using the IgnoreError property of a variable of type emailSMTPSession.
Component: wd300com.dll
Minimum version required
  • Version 15
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 05/16/2025

Send a report | Local help