4D v18

SMTP New transporter

Home

 
4D v18
SMTP New transporter

SMTP New transporter 


 

SMTP New transporter ( server ) -> Function result 
Parameter Type   Description
server  Object in Mail server information
Function result  Object in SMTP transporter object

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

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

PropertyTypeDescription
hostTextName or IP address of the host server to use for SMTP transactions. 
portNumber(optional) Port to use for SMTP transactions. Default value=587
keepAliveBoolean(optional) True to keep the connection alive until the transporter object is destroyed. Defaut value=True
connectionTimeOutNumber(optional) Maximum wait time (in seconds) to establish a connection to the server. Default value=30
sendTimeOutNumber(optional) Maximum wait time (in seconds) of a sendMail call before timeout. Default value=100
authenticationModeTextAuthentication mode used to open the session on the SMTP server(*). Possible values:
Constant Value Comment
SMTP authentication CRAM MD5 CRAM-MD5 SMTP authentication using CRAM-MD5 protocol
SMTP authentication login LOGIN SMTP authentication using LOGIN protocol
SMTP authentication plain PLAIN SMTP authentication using PLAIN protocol
userTextUser name for authentication on the server
passwordTextUser password for authentication on the server
acceptUnsecureConnectionBooleanTrue to allow 4D to establish an unencrypted connection if encrypted connection is not possible (**). If False, an error is returned if encrypted connection is not possible. Default value=False
logFileText(optional) File path for the extended log file(***). Can be relative (to the current Logs folder) or absolute
headerCharsetText(optional) Charset and encoding used for the following parts of the email: subject, attachment filenames, and email name attribute(s). Possible values:
Constant Value Comment
mail mode ISO2022JP US-ASCII_ISO-2022-JP_UTF8_QP
  • headerCharset: US-ASCII if possible, Japanese (ISO-2022-JP) & Quoted-printable if possible, otherwise UTF-8 & Quoted-printable
  • bodyCharset: US-ASCII if possible, Japanese (ISO-2022-JP) & 7-bit if possible, otherwise UTF-8 & Quoted-printable
mail mode ISO88591 ISO-8859-1
  • headerCharset: ISO-8859-1 & Quoted-printable
  • bodyCharset: ISO-8859-1 & 8-bit
mail mode UTF8 US-ASCII_UTF8_QP

headerCharset & bodyCharset: US-ASCII if possible, otherwise UTF-8 & Quoted-printable (default value)

mail mode UTF8 in base64 US-ASCII_UTF8_B64

headerCharset & bodyCharset: US-ASCII if possible, otherwise UTF-8 & base64

bodyCharsetText(optional) Charset and encoding used for the html and text body contents of the email. Possible values: Same as for headerCharset (see above)

(*) If authenticationMode is null or undefined, the most secure authentication mode supported by the server is used.

(**) Available SMTP secured ports are:

  • 465: SMTPS
  • 587 or 25: SMTP with STARTTLS upgrade if supported by the server.

(***) Unlike regular log files (enabled via the SET DATABASE PARAMETER command), extended log files store MIME contents of all sent mails and do not have any size limit. For more information, please refer to the 4DSMTPLog.txt section.

 

Returned object

The returned transporter object contains the following read-only properties and methods:

PropertyTypeDescription
transporter.hostTextName or IP address of the host server used for SMTP transactions.
transporter.portNumberPort used for SMTP transactions.
transporter.keepAliveBooleanTrue if connection is kept alive until the transporter object is destroyed.
transporter.connectionTimeOutNumberMaximum wait time (in seconds) to establish a connection to the server.
transporter.sendTimeOutNumberMaximum wait time (in seconds) of a sendMail call before timeout
transporter.acceptUnsecureConnectionBooleanTrue if 4D is allowed to establish an unencrypted connection when encrypted connection is not possible, false otherwise
transporter.authenticationModeTextAuthentication mode actually used to open the session on the SMTP server.
transporter.userTextUser name for authentication on the server
transporter.logFileTextFull path of the log file (if any)
transporter.headerCharsetTextCharset and encoding used for the header and names of the mail
transporter.bodyCharsetTextCharset and encoding used for the body of the mail

 

MethodDescription
SMTP_transporter.send( )Sends messages.
SMTP_transporter.checkConnection( )Checks authentication.

 

Note that this command does not open any connection to the SMTP server. The SMTP connection is actually opened when the SMTP_transporter.send( ) method is executed.

The SMTP connection is automatically closed:

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

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
 
 
 $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



See also 

MAIL Convert to MIME
SMTP_transporter.checkConnection( )
SMTP_transporter.send( )
transporter.acceptUnsecureConnection
transporter.authenticationMode
transporter.connectionTimeOut
transporter.host
transporter.keepAlive
transporter.logFile
transporter.port
transporter.sendTimeOut
transporter.user

 
PROPERTIES 

Product: 4D
Theme: Mail
Number: 1608

This command can be run in preemptive processes

 
HISTORY 

New
Created: 4D v17 R4
Modified: 4D v17 R5
Modified: 4D v18

 
ARTICLE USAGE

4D Language Reference ( 4D v18)