IMAP New transporter
IMAP New transporter( server : Object ) : 4D.IMAPTransporter
| Parameter | Type | Description | |
|---|---|---|---|
| parameter | Object | → | Mail server configuration |
| Result | 4D.IMAPTransporter | ← | IMAP transporter object |
History
| Release | Changes |
|---|---|
| 18 R4 | Added |
Description
The IMAP New transporter command configures a new IMAP connection according to the parameter parameter and returns a new transporter object. The returned transporter object will then usually be used to receive emails.
In the parameter parameter, pass an object containing the following properties:
| parameter | Description | Default 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 IMAP 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 | |
| .checkConnectionDelay : Integer | the maximum time (in seconds) allowed prior to checking the connection to the server | 300 | |
| .connectionTimeOut : Integer | the maximum wait time (in seconds) allowed to establish a connection to the server | 30 | |
| .host : Text | the name or the IP address of the host server | mandatory | |
| .listener: Object | allows you to manage IMAP IDLE notifications for the selected mailbox through callback functions. | none | |
| .onMailCreated : 4D.Function | Called when a new message is detected. | none | |
| .onMailDeleted : 4D.Function | Called when a message is permanently deleted. | none | |
| .onFlagsModified : 4D.Function | Called when message flags are modified. | none | |
| .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 IMAP transporter object. | none | |
| .port : Integer | the port number used for mail transactions | 993 | |
| .user : Text | the user name used for authentication on the mail server | none |
listener object
When the listener property is provided in the parameter object, the following callback functions are supported:
onMailCreated: triggered when a new message is added to the mailboxonMailDeleted: triggered when a message is permanently deletedonFlagsModified: triggered when message flags are modified
Each callback receives the following parameters:
| Parameter | Type | Description |
|---|---|---|
| transporter | Object | Current IMAP transporter |
| event | Object | Event data |
onMailCreated(transporter : Object; event : Object)
| Property | Type | Description |
|---|---|---|
| event.type | Text | "mailCreated" |
| event.mailCount | Integer | Number of messages in the mailbox |
onMailDeleted(transporter : Object; event : Object)
| Property | Type | Description |
|---|---|---|
| event.type | Text | "mailDeleted" |
| event.msgNumber | Integer | Message sequence number |
onFlagsModified(transporter : Object; event : Object)
| Property | Type | Description |
|---|---|---|
| event.type | Text | "FlagsModified" |
| event.msgNumber | Integer | Message sequence number |
| event.flags | Collection | Updated flags |
Warning: Make sure the defined timeout is lower than the server timeout, otherwise the client timeout will be useless.
Result
The function returns an IMAP transporter object. All returned properties are read-only.
The IMAP connection is automatically closed when the transporter object is destroyed.
Example
$server:=New object
$server.host:="imap.gmail.com" //Mandatory
$server.port:=993
$server.user:="4d@gmail.com"
$server.password:="XXXXXXXX"
$server.logFile:="LogTest.txt" //log to save in the Logs folder
var $transporter : 4D.IMAPTransporter
$transporter:=IMAP New transporter($server)
$status:=$transporter.checkConnection()
If(Not($status.success))
ALERT("An error occurred: "+$status.statusText)
End if
Properties
| Command number | 1723 |
| Thread safe | yes |