ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / WLanguage / WLanguage functions / Communication / Managing emails
  • POP3 and SMTP protocols
  • Authenticated SMTP
  • Timeout
  • Managing emails in asynchronous mode
  • 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 managing emails via the SMTP protocol.
Note: To open an e-mail session (via SMTP protocol only), use the EmailStartSMTPSession function.. This function can also be used to start an authenticated SMTP session.
Example
// Management of an SMTP email session
MyEmailSMTPSession is emailSMTPSession
IF MyEmailSMTPSession.StartSession() = True THEN
	UserName = MySMTPSession..Name
ELSE
	UserName = ""
	Error("Unable to establish the connection")
END
Syntax
<Result> = <Session>.OpenSession()
<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.
<Session>: emailSMTPSession variable
Name of the emailSMTPSession variable corresponding to the email session to handle.
Remarks

POP3 and SMTP protocols

The different parameters passed to <emailSMTPSession variable>.StartSession 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.

Authenticated SMTP

The SMTP authentication cannot be performed by <emailSMTPSession variable>.StartSession. 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 ("Configuration" tab).
  2. Enable the asynchronous mode when starting the SMTP session (with EmailStartSMTPSession or <emailSMTPSession variable>.StartSession).
  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 emptied: pending emails are not sent and are removed from the spooler.
If "Disable the email spooler" is checked while emails are still found in the spooler, these emails will not be lost: the administrator keeps sending them but no new email is accepted by the spooler.
Warning: Asynchronous mode can only be used when opening a session on an SMTP server (function EmailStartSMTPSession for sending emails or function <emailSMTPSession variable>.StartSession).. The asynchronous mode is ignored in all other cases.

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 <emailSMTPSession variable>.StartSession:
// 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.
Component: wd300com.dll
Minimum version required
  • Version 24
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 02/20/2025

Send a report | Local help