|
|
|
|
|
- POP3 and SMTP protocols
- Authenticated SMTP
- Connection with two-factor authentication
- Timeout
- Creating an Outlook Exchange profile
- Managing emails in asynchronous mode
- Gmail: What should I do if a connection to Gmail (SMTP, IMAP, POP3) fails due to a certificate error?
EmailStartSession (Function) In french: EmailOuvreSession Starts an email management session based on the selected management mode: - e-mails managed by POP3, SMTP or IMAP protocol: the EmailStartSession function opens the POP3, SMTP or IMAP session.
- emails managed via the MS Exchange client: the EmailStartSession function opens the MS Exchange session. In this case, the current directory is automatically modified when using EmailStartSession.
Remarks:
IF EmailStartSession(USER, PASSWORD, "pop3.gmail.com", "smtp.gmail.com") = True THEN
UserName = USER
ELSE
UserName = ""
Error("Unable to establish the connection")
END
Syntax
Starting an email session (POP3, SMTP, IMAP, Notes or Outlook) Hide the details
<Result> = EmailStartSession(<Session>)
| Note: This syntax has been retained for compatibility.. We recommend that you use the emailPOP3Session, emailSMTPSession variables or EmailStartPOP3Session and EmailStartSMTPSession.
Starting an email session by using the POP3 and SMTP protocols simultaneously Hide the details
<Result> = EmailStartSession(<Username> , <Password> , <Address of POP3 server> [, <Address of SMTP server> [, <Number of POP3 port> [, <Number of SMTP port> [, <Asynchronous>]]]])
<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 user. 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 2025Secret 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. <Address of POP3 server>: Character string IP address of email server (incoming protocol). This IP address is supplied by the service provider or by the network administrator. This IP address can have the following format:- IP address in XXX.XXX.XXX.XXX format (125.5.110.100 for example).
- IP address containing the server name (pop3.freesbee.eu for example). This syntax is recommended.
- IP address returned by NetIPAddress.
<Address of SMTP server>: Optional character string IP address of email server (outgoing protocol). This IP address is supplied by the service provider or by the network administrator. This address must be specified only if the POP3 account and the SMTP account do not go through the same computer. <Number of POP3 port>: Optional integer Identifies the port used for the POP3 protocol (110 by default). <Number of SMTP port>: Optional integer Identifies the port used for SMTP (25 by default). <Asynchronous>: Optional constant or boolean | | emailAsynchronous or True | The emails sent during the session started by EmailStartSession must be transmitted in asynchronous mode (see the Notes). | emailSynchronous or False (Default value) | The emails sent during the session started by EmailStartSession must be transmitted in synchronous mode (see the Notes). |
|
Remarks POP3 and SMTP protocols The different parameters passed to EmailStartSession 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 direct connection to Internet (cable or ADSL): no specific operation required.
- The user uses a modem to connect to the Internet: the NetOpenRemoteAccess function opens the Internet connection.
By default, if only the IP address of POP3 server is specified, this address will be used by the email server that uses SMTP. The IP address of SMTP protocol must be specified only if the POP3 account and the SMTP account do not use the same computer. 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: // 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 IF EmailStartSession(gMaSessionIMAP) 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 EmailStartSession:
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.
This page is also available for…
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|