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
| Parameter | Type | Description | |
|---|---|---|---|
| server | Object | -> | Mail server information | 
| Result | 4D.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
| Release | Changes | 
|---|---|
| 17 R4 | Added | 
.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 transporterobject is destroyed if the.keepAliveproperty is true,
- after each .send( )function execution if the.keepAliveproperty is set to false.
.send()
History
| Release | Changes | 
|---|---|
| 17 R5 | Support of mime contents | 
| 17 R4 | Added | 
.send*( mail : Object ) : Object
| Parameter | Type | Description | |
|---|---|---|---|
| Object | -> | Email to send | |
| Result | Object | <- | 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
transporterobject must have already been created using theSMTP New transportercommand.
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:
| Property | Type | Description | 
|---|---|---|
| success | boolean | True if the send is successful, False otherwise | 
| status | number | Status code returned by the SMTP server (0 in case of an issue unrelated to the mail processing) | 
| statusText | text | Status 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:
| Property | Value | 
|---|---|
| success | False | 
| status | 0 | 
| statusText | "Failed to send email" |