Skip to main content
Version: 20 R7 BETA

SMTP New transporter

SMTP New transporter( server : Object ) : 4D.SMTPTransporter

ParameterTypeDescription
serverObjectMail server information
Function result4D.SMTPTransporterSMTP transporter object
History
ReleaseChanges
18New logFile property
17 R5New bodyCharset and headerCharset properties
17 R4Added

Description

The SMTP New transporter command configures a new SMTP connection according to the server parameter and returns a new SMTP transporter object object. The returned transporter object will then usually be used to send emails.

This command does not open any connection to the SMTP server. The SMTP connection is actually opened when the .send() function is executed.

The SMTP connection is automatically closed:

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

In the server parameter, pass an object containing the following properties:

serverDefault value (if omitted)
.acceptUnsecureConnection : Boolean
True if 4D is allowed to establish an unencrypted connection
False
.accessTokenOAuth2: Text
.accessTokenOAuth2: Object
Text string or token object representing OAuth2 authorization credentials. Used only with OAUTH2 authenticationMode. If accessTokenOAuth2 is used but authenticationMode is omitted, the OAuth 2 protocol is used (if allowed by the server). Not returned in SMTP transporter object.
none
.authenticationMode : Text
the authentication mode used to open the session on the mail server
the most secure authentication mode supported by the server is used
.bodyCharset : Text
the charset and encoding used for the body part of the email
mail mode UTF8 (US-ASCII_UTF8_QP)
.connectionTimeOut : Integer
the maximum wait time (in seconds) allowed to establish a connection to the server
30
.headerCharset : Text
the charset and encoding used for the email header
mail mode UTF8 (US-ASCII_UTF8_QP)
.host : Text
the name or the IP address of the host server
mandatory
.keepAlive : Boolean
True if the SMTP connection must be kept alive until the transporter object is destroyed
True
.logFile : Text
the path of the extended log file defined (if any) for the mail connection
none
password : Text
User password for authentication on the server. Not returned in SMTP transporter object.
none
.port : Integer
the port number used for mail transactions
587
.sendTimeOut : Integer
the maximum wait time (in seconds) of a call to .send( ) before a timeout occurs
100
.user : Text
the user name used for authentication on the mail server
none

Result

The function returns a SMTP transporter object. All returned properties are read-only.

Example

 $server:=New object
$server.host:="smtp.gmail.com" //Mandatory
$server.port:=465
$server.user:="4D@gmail.com"
$server.password:="XXXX"
$server.logFile:="LogTest.txt" //Extended log to save in the Logs folder

var $transporter : 4D.SMTPTransporter
$transporter:=SMTP New transporter($server)

$email:=New object
$email.subject:="my first mail "
$email.from:="4d@gmail.com"
$email.to:="4d@4d.com;test@4d.com"
$email.textBody:="Hello World"
$email.htmlBody:="<h1>Hello World</h1><h4>'Neque porro quisquam est qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit...'</h4>\
<p>There are many variations of passages of Lorem Ipsum available."\
+"The generated Lorem Ipsum is therefore always free from repetition, injected humour, or non-characteristic words etc.</p>"

$status:=$transporter.send($email)
If(Not($status.success))
ALERT("An error occurred sending the mail: "+$status.message)
End if

Properties

Command number1608
Thread safe