Skip to main content
Version: 20 R10

SMTPTransporter

The SMTPTransporter class allows you to configure SMTP connections and send emails through SMTP transporter objects.

SMTP Transporter object

SMTP Transporter objects are instantiated with the SMTP New transporter command. They provide the following properties and functions:














4D.SMTPTransporter.new()

4D.SMTPTransporter.new*( server : Object ) : 4D.SMTPTransporter

ParameterTypeDescription
serverObject->Mail server information
Result4D.SMTPTransporter<-SMTP transporter object

Description

The 4D.SMTPTransporter.new() function creates and returns a new object of the 4D.SMTPTransporter type. It is identical to the SMTP New transporter command (shortcut).

For information about SMTP status codes, please refer to this page.

Example

 var $pw : Text
var $options : Object
var $transporter : 4D.SMTPTransporter
$options:=New object

$pw:=Request("Please enter your password:")
$options.host:="smtp.gmail.com"

$options.user:="test@gmail.com"
$options.password:=$pw

$transporter:=SMTP New transporter($options)

$status:=$transporter.checkConnection()
If($status.success=True)
ALERT("SMTP connection check successful!")
Else
ALERT("Error # "+String($status.status)+", "+$status.statusText)
End if

.keepAlive

History
ReleaseChanges
17 R4Added

.keepAlive* : Boolean

Description

The .keepAlive property contains True if the SMTP connection must be kept alive until the transporter object is destroyed, and False otherwise. By default, if the keepAlive property has not been set in the server object (used to create the transporter object with SMTP New transporter), it is True.

The SMTP connection is automatically closed:

  • when the transporter object is destroyed if the .keepAlive property is true,
  • after each .send( ) function execution if the .keepAlive property is set to false.

.send()

History
ReleaseChanges
17 R5Support of mime contents
17 R4Added

.send*( mail : Object ) : Object

ParameterTypeDescription
mailObject->Email to send
ResultObject<-SMTP status

Description

The .send() function sends the mail object to the SMTP server defined in the transporter object and returns a status object.

The transporter object must have already been created using the SMTP New transporter command.

The method creates the SMTP connection if it is not already alive. If the .keepAlive property of the transporter object is false, the SMTP connection is automatically closed after the execution of .send(), otherwise it stays alive until the transporter object is destroyed. For more information, please refer to the SMTP New transporter command description.

In mail, pass a valid Email object to send. The origination (where the email is coming from) and destination (one or more recipients) properties must be included, the remaining properties are optional.

Returned object

The function returns an object describing the SMTP status of the operation. This object can contain the following properties:

PropertyTypeDescription
successbooleanTrue if the send is successful, False otherwise
statusnumberStatus code returned by the SMTP server (0 in case of an issue unrelated to the mail processing)
statusTexttextStatus message returned by the SMTP server

In case of an issue unrelated to the SMTP processing (e.g. a mandatory property is missing in mail), 4D generates an error that you can intercept using a method installed by the ON ERR CALL command. Use the Last errors command for information about the error.

In this case, the resulting status object contains the following values:

PropertyValue
successFalse
status0
statusText"Failed to send email"