PC SOFT

ONLINE HELP
FOR WINDEV, WEBDEV AND WINDEV MOBILE

  • SMTP protocol
  • Session and user name
  • Authenticated SMTP
  • Time-out
  • Required application feature
  • Managing emails in asynchronous mode
  • Gmail: What to do if a connection to Gmail (SMTP, IMAP, POP3) fails with a certificate error?
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadApple WatchUniversal Windows 10 AppWindows Mobile
Others
Stored procedures
Starts a session for sending emails with the SMTP protocol. You will only have the ability to send emails.
Versions 17 and later
iPhone/iPad This function is now available for the iPhone/iPad applications.
New in version 17
iPhone/iPad This function is now available for the iPhone/iPad applications.
iPhone/iPad This function is now available for the iPhone/iPad applications.
Versions 21 and later
Universal Windows 10 App This function is now available in Universal Windows 10 App mode.
New in version 21
Universal Windows 10 App This function is now available in Universal Windows 10 App mode.
Universal Windows 10 App This function is now available in Universal Windows 10 App mode.
Notes:
  • 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.
Versions 22 and later
Android Widget This function is now available in Android Widget mode.
Android This function is now available for the Android applications.
New in version 22
Android Widget This function is now available in Android Widget mode.
Android This function is now available for the Android applications.
Android Widget This function is now available in Android Widget mode.
Android This function is now available for the Android applications.
Example
// Send an email via a non-secure SMTP server
EmailSetTimeOut(10) //10 seconds for the time-out
// Caution: you must use the SMTP server of the Internet provider
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 time-out, check the parameters of " + ...
"""Firewall"" on the port used (25)")
END
WINDEVWEBDEV - Server codeReports and QueriesWindowsAjaxUser code (UMC)
UserName is string

UserName = "myaddress@gmail.com"
// Send an email via the secure SMTP protocol
EmailSetTimeOut(10) //10 seconds for the time-out
// 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, emailOptionSecuredTLS) = 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 time-out, check the parameters of the "+ ...
"""Firewall"" on the port used (587)")
END
Syntax
<Result> = EmailStartSMTPSession(<User Name> [, <Password>] , <Address of SMTP Server> [, <Number of SMTP Port> [, <Asynchronous Mode> [, <Option>]]])
<Result>: Boolean
  • True if the session was started,
  • False otherwise. The ErrorOccurred variable is set to True if an error occurred.
    To find out the error details, use ErrorInfo associated with the errMessage constant.
<User Name>: Character string (with quotes)
Identifies the email session in the functions for email management (used by EmailSendMessage to send emails for example).
<Password>: Optional character string (with quotes)
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.
<Address of SMTP Server>: Character string (with quotes)
DNS name or IP address of email server (outgoing protocol). This IP address is supplied by the service provider or by the network administrator.
Caution: You must use the SMTP server of the provider of Internet connection. 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 the SMTP protocol (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.
WINDEVAndroidAndroid Widget iPhone/iPadWindows MobileUniversal Windows 10 AppJava 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.
Versions 15 and later
emailOptionSecuredTLS
New in version 15
emailOptionSecuredTLS
emailOptionSecuredTLS
Start the SMTP session secured by the TLS protocol.
LinuxAndroidAndroid Widget iPhone/iPadWindows MobileUniversal Windows 10 App This constant is not available.
Windows MobileUniversal Windows 10 App This constant is not available.
Versions 20 and later
OptionSSL
New in version 20
OptionSSL
OptionSSL
Start the SMTP session secured by the SSL protocol. This type of session is used by the Orange, Free and Gmail servers for example.
LinuxAndroidAndroid Widget iPhone/iPadWindows MobileUniversal Windows 10 App This constant is not available.
Windows MobileUniversal Windows 10 App This constant is not available.
Java This parameter is not available.
Remarks

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 is using a modem to connect to Internet: NetOpenRemoteAccess is used to establish the connection to Internet.
    • The user is using a direct connection to Internet (cable or ADSL): no specific operation is required.
  • The SMTP protocol can only be used to send emails. A WLanguage error occurs if you try to read the emails without starting a POP3 session (EmailStartPOP3Session). To start a POP3 session and an SMTP session at the same time, use EmailStartSession.

Session and user name

Once an SMTP session was started, you have the ability to start a POP3 session (EmailStartPOP3Session) by using the same user name.

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: the SMTP authentication cannot be performed by EmailStartSession. To start a POP3 session and an authenticated SMTP session at the same time, you must use both EmailStartPOP3Session and EmailStartSMTPSession.

Time-out

The time-out can be configured by EmailSetTimeOut.
Versions 21 and later
Universal Windows 10 App

Required application feature

The use of this function triggers the declaration of an application feature in the wizard for generating the application.
Required feature: Family and corporate networks
This feature allows the applications to use incoming and outgoing accesses to the family and corporate networks.
New in version 21
Universal Windows 10 App

Required application feature

The use of this function triggers the declaration of an application feature in the wizard for generating the application.
Required feature: Family and corporate networks
This feature allows the applications to use incoming and outgoing accesses to the family and corporate networks.
Universal Windows 10 App

Required application feature

The use of this function triggers the declaration of an application feature in the wizard for generating the application.
Required feature: Family and corporate networks
This feature allows the applications to use incoming and outgoing accesses to the family and corporate networks.
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 ("Advanced" tab).
  2. Enable the asynchronous mode when starting the SMTP session (with EmailStartSMTPSession or EmailStartSession).
  3. All the outgoing emails will be transmitted to a "spooler". The emails are queued up before they are sent.
The execution of Email functions do not lock the rest of your program anymore. EmailStatus is used to find out the email status.
Note: If the WEBDEV administrator is closed, the email spooler is cleared: the pending emails are not sent and they are removed form 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.
Caution: The asynchronous mode can only be used when starting a session on an SMTP server (EmailStartSMTPSession for sending emails or EmailStartSession). The asynchronous mode is ignored in all the other cases.

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 EmailStartSMTPSession:
// Enable the multi-platform implementation
EmailConfigure(emailParameterMode, 1)
Note: 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.
Related Examples:
Pocket Managing Contacts Mobile (WINDEV Mobile): Pocket Managing Contacts
[ + ] This example presents the management of contacts in Pocket PC.
The following topics will be presented in this example:
1/ the loopers
2/ the use of queries
3/ sending SMSs
4/ sending emails
5/ the phone call.
Components
WINDEVWEBDEV - Server codeReports and Queries wd230com.dll
Windows Mobile wp230com.dll
Java wd230java.jar
Linux wd230com.so
Android wd230android.jar
Minimum required version
  • Version 9
This page is also available for…
Comments
ERRO CERTIFICACAO ARRUMADO
EmailConfigure(emailParameterMode,1)
// ESSA CONFIGURACAO ACIMA ARRUMA ERRO CERTIFICACAO
EmailSetTimeOut(30)
HourGlass()
n_email_sessao is boolean=EmailStartSMTPSession(EDT_USUARIO,EDT_SENHA,EDT_SERVIDOR_SMTP,EDT_porta,False,emailOptionSecuredTLS)
IF n_email_sessao=True THEN
_minha_mensagem is an Email // est un Email
_minha_mensagem..Sender=EDT_EmailSender
Add(_minha_mensagem..Recipient, EDT_destinatario)
_minha_mensagem..Subject = EDT_ASSUNTO
_minha_mensagem..Message = EDT_MENSAGEM
_minha_mensagem..SenderAddress = EDT_EmailSender
_minha_mensagem..ReturnReceipt = True
EmailLoadAttachment(_minha_mensagem,EDT_anexo)
IF EmailSendMessage(EDT_USUARIO, _minha_mensagem) = False THEN
Info("Erro Mandar Mesnagem:"+CR+ErrorInfo())
END
EmailCloseSession(EDT_USUARIO)
END
HourGlass(False)
// blog com video e exemplo
// http://windevdesenvolvimento.blogspot.com.br/2017/10/aula-1277-email-3-erro-certificacao.html
// https://www.youtube.com/watch?v=LxqfFegkGqo

De matos
Oct. 29 2017