Skip to main content
Version: 20 R10

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)

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

the most secure authentication mode supported by the server is used

mail mode UTF8 (US-ASCII_UTF8_QP)

30

mail mode UTF8 (US-ASCII_UTF8_QP)

mandatory

True

none
password : Text
User password for authentication on the server. Not returned in SMTP transporter object.
none

587

100

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