AYUDA EN LÍNEA
 WINDEVWEBDEV Y WINDEV MOBILE

Este contenido se ha traducido automáticamente.  Haga clic aquí  para ver la versión en inglés.
Ayuda / WLanguage / Funciones WLanguage / Comunicación / Gestión de correos electrónicos
  • SMTP protocol
  • Session and username
  • Authenticated SMTP
  • Timeout
  • Gmail: What should I do if a connection to Gmail (SMTP, IMAP, POP3) fails due to a certificate error?
WINDEV
WindowsLinuxJavaReportes y ConsultasCódigo de Usuario (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Código Navegador
WINDEV Mobile
AndroidWidget Android iPhone/iPadIOS WidgetApple WatchMac Catalyst
Otros
Procedimientos almacenados
Starts a session for sending emails via 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.
Ejemplo
// Send an email via a non-secure SMTP server
EmailSetTimeOut(10) //10 seconds for the timeout
// Warning: you must use your ISP's SMTP server 
let sSMTPServers = "smtp.orange.fr"
IF EmailStartSMTPSession(sUserName, sPassword, sSMTPServer) = True THEN
	// Procedure used to initialize the email structure
	Initialize_Email()
	// Sends the email
	IF EmailSendMessage(sUserName) = False THEN
		Error()
	END
	EmailCloseSession(sUserName)
ELSE
	Error("Unable to establish connection", ErrorInfo(), ...
		"In case of timeout, check the parameters of " + ...
		"""Firewall"" on the port used (25)")
END
WINDEVWindowsCódigo de Usuario (UMC)
UserName is string

UserName = "myaddress@gmail.com"
// Send an email via the secure SMTP protocol
EmailSetTimeOut(10) //10 seconds for the timeout
// Use a secure SMTP server with authentication
// Required to use a SMTP 
// that differs from the one of the ISP
IF EmailStartSMTPSession(UserName, "Password", ...
			"smtp.gmail.com", 587, False, emailProtocolSMTPS) = True THEN
	// Procedure used to initialize the email structure
	Initialize_Email()
	// Sends the email
	IF EmailSendMessage(UserName) = False THEN
		Error()
	END
	EmailCloseSession(UserName)
ELSE
	Error("Unable to establish connection", ErrorInfo(), ...
		"In case of timeout, check the parameters of the "+ ...
		"""Firewall"" on the port used (587)")
END
Sintaxis
<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 string or Secret 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.
Novedad versión 2025
Cadenas secretas: Si utiliza el almacén de cadenas secretas, el tipo de cadena secreta utilizado para este parámetro debe ser "ANSI o Unicode string".
Para obtener más información sobre las cadenas secretas y el almacén, consulte Almacén de cadenas secretas.
<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.
Warning You must use the SMTP server of your Internet connection provider. 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 SMTP (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.

WINDEVJava This parameter must correspond to emailSynchronous or False.
<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.
In version 28 Update 4, this constant was renamed for better code readability.. In previous versions, this constant corresponds to emailOptionSecuredTLS.
optionTLSStart the SMTP session secured by the SSL protocol. This type of session is used by the Orange, Free and Gmail servers for example.
In version 28 Update 4, this constant was renamed for better code readability.. In previous versions, this constant corresponds to optionSSL.

Java This parameter is not available.
Observaciones

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 the Internet: the NetOpenRemoteAccess function opens the Internet connection.
    • The user uses a direct connection to Internet (cable or ADSL): no specific operation 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.
Note: SMTP authentication cannot be performed with the EmailStartSession function.. 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.

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 EmailStartSMTPSession:
// Enable the multi-platform implementation
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.
Clasificación Lógica de negocio / UI: Lógica de negocio
Componente: wd300com.dll
Versión mínima requerida
  • Versión 9
Esta página también está disponible para…
Comentarios
Haga clic en [Agregar] para publicar un comentario

Última modificación: 16/05/2025

Señalar un error o enviar una sugerencia | Ayuda local