Skip to main content
Version: Next

IMAP New transporter

IMAP New transporter( parameter : Object ) : 4D.IMAPTransporter

ParameterTypeDescription
parameterObject→Mail server configuration
Result4D.IMAPTransporter←IMAP transporter object
History
ReleaseChanges
18 R4Added

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:

parameterDescriptionDefault value (if omitted)
.acceptUnsecureConnection : BooleanTrue if 4D is allowed to establish an unencrypted connectionFalse
.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 : Textthe authentication mode used to open the session on the mail serverthe most secure authentication mode supported by the server is used
.checkConnectionDelay : Integerthe maximum time (in seconds) allowed prior to checking the connection to the server300
.connectionTimeOut : Integerthe maximum wait time (in seconds) allowed to establish a connection to the server30
.host : Textthe name or the IP address of the host servermandatory
.listener: Objectallows you to manage IMAP IDLE notifications for the selected mailbox through callback functions.none
.onMailCreated : 4D.FunctionCalled when a new message is detected.none
.onMailDeleted : 4D.FunctionCalled when a message is permanently deleted.none
.onFlagsModified : 4D.FunctionCalled when message flags are modified.none
.logFile : Textthe path of the extended log file defined (if any) for the mail connectionnone
.password : TextUser password for authentication on the server. Not returned in IMAP transporter object.none
.port : Integerthe port number used for mail transactions993
.user : Textthe user name used for authentication on the mail servernone

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 mailbox
  • onMailDeleted: triggered when a message is permanently deleted
  • onFlagsModified: triggered when message flags are modified

Each callback receives the following parameters:

ParameterTypeDescription
transporterObjectCurrent IMAP transporter
eventObjectEvent data

onMailCreated(transporter : Object; event : Object)​

PropertyTypeDescription
event.typeText"mailCreated"
event.mailCountIntegerNumber of messages in the mailbox

onMailDeleted(transporter : Object; event : Object)​

PropertyTypeDescription
event.typeText"mailDeleted"
event.msgNumberIntegerMessage sequence number

onFlagsModified(transporter : Object; event : Object)​

PropertyTypeDescription
event.typeText"FlagsModified"
event.msgNumberIntegerMessage sequence number
event.flagsCollectionUpdated 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 number1723
Thread safeyes