| 4D v18SMTP New transporter | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 
 | 
    4D v18
 SMTP New transporter 
         | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| SMTP New transporter ( server ) -> Function result | ||||||||
| Parameter | Type | Description | ||||||
| server | Object |   | Mail server information | |||||
| Function result | Object |   | 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:
| Property | Type | Description | |||||||||||||||
| host | Text | Name or IP address of the host server to use for SMTP transactions. | |||||||||||||||
| port | Number | (optional) Port to use for SMTP transactions. Default value=587 | |||||||||||||||
| keepAlive | Boolean | (optional) True to keep the connection alive until the transporter object is destroyed. Defaut value=True | |||||||||||||||
| connectionTimeOut | Number | (optional) Maximum wait time (in seconds) to establish a connection to the server. Default value=30 | |||||||||||||||
| sendTimeOut | Number | (optional) Maximum wait time (in seconds) of a sendMail call before timeout. Default value=100 | |||||||||||||||
| authenticationMode | Text | Authentication mode used to open the session on the SMTP server(*). Possible values: 
 | |||||||||||||||
| user | Text | User name for authentication on the server | |||||||||||||||
| password | Text | User password for authentication on the server | |||||||||||||||
| acceptUnsecureConnection | Boolean | True 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 | |||||||||||||||
| logFile | Text | (optional) File path for the extended log file(***). Can be relative (to the current Logs folder) or absolute | |||||||||||||||
| headerCharset | Text | (optional) Charset and encoding used for the following parts of the email: subject, attachment filenames, and email name attribute(s). Possible values: 
 | |||||||||||||||
| bodyCharset | Text | (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:
(***) 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:
| Property | Type | Description | 
| transporter.host | Text | Name or IP address of the host server used for SMTP transactions. | 
| transporter.port | Number | Port used for SMTP transactions. | 
| transporter.keepAlive | Boolean | True if connection is kept alive until the transporter object is destroyed. | 
| transporter.connectionTimeOut | Number | Maximum wait time (in seconds) to establish a connection to the server. | 
| transporter.sendTimeOut | Number | Maximum wait time (in seconds) of a sendMail call before timeout | 
| transporter.acceptUnsecureConnection | Boolean | True if 4D is allowed to establish an unencrypted connection when encrypted connection is not possible, false otherwise | 
| transporter.authenticationMode | Text | Authentication mode actually used to open the session on the SMTP server. | 
| transporter.user | Text | User name for authentication on the server | 
| transporter.logFile | Text | Full path of the log file (if any) | 
| transporter.headerCharset | Text | Charset and encoding used for the header and names of the mail | 
| transporter.bodyCharset | Text | Charset and encoding used for the body of the mail | 
| Method | Description | 
| 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:
 $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
									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
									
	Product:  4D
	Theme:  Mail
	Number:  
        1608
        
        
        
	

	Created:  4D v17 R4
	Modified:  4D v17 R5
	Modified:  4D v18
	4D Language Reference ( 4D v18)
	
	
	
 Add a comment
Add a comment