|
|
|
|
|
- Timeout
- Connection with two-factor authentication
- Required application feature
- Gmail: What to do if a connection to Gmail (SMTP, IMAP, POP3) fails with a certificate error?
EmailStartIMAPSession (Function) In french: EmailOuvreSessionIMAP 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.
// 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 User password. This password is given by the service provider or by the network administrator. <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 given in the following format:- 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.
Remark: The address must be a 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. | optionTLS | TLS connection required (in the case of a secure IMAP server). Remark: In most cases, the port used for a secured IMAP server is port 993 (instead of port 143, the default port value). Before version 28 Update 4, this constant was named optionSSL. |
Remarks Connection with two-factor authentication More and more providers offer secure email accounts (SMTP/IMAP) with two-factor authentication. Here is how it works: - Connect to the email provider using OAuth: 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:
OAuthCnxGoogle est un OAuth2Paramètres
gMaSessionIMAP est un emailSessionIMAP
gMaSessionIMAP.AdresseServeur = "imap.gmail.com"
gMaSessionIMAP.Option = optionTLS
gMaSessionIMAP.Port = "993"
OAuthCnxGoogle.ClientID = "ID de l'application"
OAuthCnxGoogle.ClientSecret = "ID secret de l’application"
OAuthCnxGoogle.URLAuth = "https://accounts.google.com/o/oauth2/auth"
OAuthCnxGoogle.URLToken = "https://accounts.google.com/o/oauth2/token"
OAuthCnxGoogle.Scope = "https://mail.google.com/"
OAuthCnxGoogle.URLRedirection = "http://localhost:9000"
OAuthCnxGoogle.TypeRéponse = "code"
gMaSessionIMAP.AuthToken = AuthIdentifie(OAuthCnxGoogle)
SI gMaSessionIMAP.AuthToken <> Null ALORS
SI gMaSessionIMAP.OuvreSession() ALORS
SINON
FIN
SINON
FIN
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 EmailStartIMAPSession:
EmailConfigure(emailParameterMode, 1)
Remarks: - 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.
- You can handle certificate errors on an SMTP session using the IgnoreError property of a variable of type emailSMTPSession.
This page is also available for…
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|