POP3Transporter
The POP3Transporter class allows you to retrieve messages from a POP3 email server.
POP3 Transporter object
POP3 Transporter objects are instantiated with the POP3 New transporter command. They provide the following properties and functions:
POP3 New transporter
History
| Release | Changes | 
|---|---|
| 18 R2 | Added | 
POP3 New transporter*( server : Object ) : 4D.POP3Transporter
| Parameter | Type | Description | |
|---|---|---|---|
| server | object | -> | Mail server information | 
| Result | 4D.POP3Transporter | <- | POP3 transporter object | 
Description
The POP3 New transporter command configures a new POP3 connectionaccording to the server parameter and returns a new POP3 transporter object. The returned transporter object will then usually be used to receive emails.
In the server parameter, pass an object containing the following properties:
| server | Default value (if omitted) | 
|---|---|
| False | |
| .accessTokenOAuth2: Text String representing OAuth 2 authorization credentials. Used only with OAUTH2 authenticationMode. IfaccessTokenOAuth2is used butauthenticationModeis 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 | |
| 30 | |
| mandatory | |
| none | |
| .password : Text User password for authentication on the server. Not returned in SMTP transporter object. | none | 
| 995 | |
| none | 
Result
The function returns a POP3 transporter object. All returned properties are read-only.
The POP3 connection is automatically closed when the transporter object is destroyed.
Example
 var $server : Object
 $server:=New object
 $server.host:="pop.gmail.com" //Mandatory
 $server.port:=995
 $server.user:="4d@gmail.com"
 $server.password:="XXXXXXXX"
 $server.logFile:="LogTest.txt" //log to save in the Logs folder
 var $transporter : 4D.POP3Transporter
 $transporter:=POP3 New transporter($server)
 $status:=$transporter.checkConnection()
 If(Not($status.success))
    ALERT("An error occurred receiving the mail: "+$status.statusText)
 End if
4D.POP3Transporter.new()
4D.POP3Transporter.new*( server : Object ) : 4D.POP3Transporter
| Parameter | Type | Description | |
|---|---|---|---|
| server | Object | -> | Mail server information | 
| Result | 4D.POP3Transporter | <- | POP3 transporter object | 
Description
The 4D.POP3Transporter.new() function creates and returns a new object of the 4D.POP3Transporter type. It is identical to the POP3 New transporter command (shortcut).
Example
 var $pw :  Text
 var $options : Object
 $options:=New object
 $pw:=Request("Please enter your password:")
 if(OK=1)
    $options.host:="pop3.gmail.com"
    $options.user:="test@gmail.com"
    $options.password:=$pw
    $transporter:=POP3 New transporter($options)
    $status:=$transporter.checkConnection()
    If($status.success)
       ALERT("POP3 connection check successful!")
    Else
       ALERT("Error: "+$status.statusText)
    End if
 End if
.delete()
History
| Release | Changes | 
|---|---|
| 18 R2 | Added | 
.delete*( msgNumber : Integer )
| Parameter | Type | Description | |
|---|---|---|---|
| msgNumber | Integer | -> | Number of the message to delete | 
Description
The .delete( ) function flags the msgNumber email for deletion from the POP3 server.
In the msgNumber parameter, pass the number of the email to delete. This number is returned in the number property by the .getMailInfoList() method.
Executing this method does not actually remove any email. The flagged email will be deleted from the POP3 server only when the POP3_transporter object (created with POP3 New transporter) is destroyed. The flag could be also be removed using the .undeleteAll() method.
If the current session unexpectedly terminates and the connection is closed (e.g., timeout, network failure, etc.), an error message is generated and messages marked for deletion will remain on the POP3 server.
Example
 $mailInfoList:=$POP3_transporter.getMailInfoList()
 For each($mailInfo;$mailInfoList)
  // Mark your mail as "to be deleted at the end of the session"
    $POP3_transporter.delete($mailInfo.number)
 End for each
  // Force the session closure to delete the mails marked for deletion
 CONFIRM("Selected messages will be deleted.";"Delete";"Undo")
 If(OK=1) //deletion confirmed
    $POP3_transporter:=Null
 Else
    $POP3_transporter.undeleteAll() //remove deletion flags
 End if
.getBoxInfo()
History
| Release | Changes | 
|---|---|
| 18 R2 | Added | 
.getBoxInfo()* : Object
| Parameter | Type | Description | |
|---|---|---|---|
| Result | Object | <- | boxInfo object | 
Description
The .getBoxInfo() function returns a boxInfo object corresponding to the mailbox designated by the POP3 transporter. This function allows you to retrieve information about the mailbox.
The boxInfo object returned contains the following properties:
| Property | Type | Description | 
|---|---|---|
| mailCount | Number | Number of messages in the mailbox | 
| size | Number | Message size in bytes | 
Example
 var $server; $boxinfo : Object
 $server:=New object
 $server.host:="pop.gmail.com" //Mandatory
 $server.port:=995
 $server.user:="4d@gmail.com"
 $server.password:="XXXXXXXX"
 $transporter:=POP3 New transporter($server)
  //mailbox info
 $boxInfo:=$transporter.getBoxInfo()
 ALERT("The mailbox contains "+String($boxInfo.mailCount)+" messages.")
.getMail()
History
| Release | Changes | 
|---|---|
| 18 R2 | Added | 
.getMail*( msgNumber : Integer ) : Object
| Parameter | Type | Description | |
|---|---|---|---|
| msgNumber | Integer | -> | Number of the message in the list | 
| Result | Object | <- | Email object | 
Description
The .getMail() function returns the Email object corresponding to the msgNumber in the mailbox designated by the POP3 transporter. This function allows you to locally handle the email contents.
Pass in msgNumber the number of the message to retrieve. This number is returned in the number property by the .getMailInfoList() function.
The method returns Null if:
- msgNumber designates a non-existing message,
- the message was marked for deletion using .delete( ).
Returned object
.getMail() returns an Email object.
Example
You want to know the sender of the first mail of the mailbox:
 var $server; $transporter : Object
 var $mailInfo : Collection
 var $sender : Variant
 $server:=New object
 $server.host:="pop.gmail.com" //Mandatory
 $server.port:=995
 $server.user:="4d@gmail.com"
 $server.password:="XXXXXXXX"
 $transporter:=POP3 New transporter($server)
 $mailInfo:=$transporter.getMailInfoList()
 $sender:=$transporter.getMail($mailInfo[0].number).from
.getMailInfo()
History
| Release | Changes | 
|---|---|
| 18 R2 | Added | 
.getMailInfo*( msgNumber : Integer ) : Object
| Parameter | Type | Description | |
|---|---|---|---|
| msgNumber | Integer | -> | Number of the message in the list | 
| Result | Object | <- | mailInfo object | 
Description
The .getMailInfo() function returns a mailInfo object corresponding  corresponding to the msgNumber in the mailbox designated by the POP3 transporter. This function allows you to retrieve information about the email.
In msgNumber, pass the number of the message to retrieve. This number is returned in the number property by the .getMailInfoList() method.
The mailInfo object returned contains the following properties:
| Property | Type | Description | 
|---|---|---|
| size | Number | Message size in bytes | 
| id | Text | Unique ID of the message | 
The method returns Null if:
- msgNumber designates a non-existing message,
- the message was marked for deletion using .delete( ).
Example
 var $server; $mailInfo : Object
 var $mailNumber : Integer
 $server.host:="pop.gmail.com" //Mandatory
 $server.port:=995
 $server.user:="4d@gmail.com"
 $server.password:="XXXXXXXX"
 var $transporter : 4D.POP3Transporter
 $transporter:=POP3 New transporter($server)
  //message info
 $mailInfo:=$transporter.getMailInfo(1) //get the first mail
 If($mailInfo #Null)
    ALERT("First mail size is:"+String($mailInfo.size)+" bytes.")
 End if
.getMailInfoList()
History
| Release | Changes | 
|---|---|
| 18 R2 | Added | 
.getMailInfoList()* : Collection
| Parameter | Type | Description | |
|---|---|---|---|
| Result | Collection | <- | Collection of mailInfoobjects | 
Description
The .getMailInfoList() function returns a collection of mailInfo objects describing all messages in the mailbox designated by the POP3 transporter. This function allows you to locally manage the list of messages located on the POP3 mail server.
Each mailInfo object in the returned collection contains the following properties:
| Property | Type | Description | 
|---|---|---|
| [ ].size | Number | Message size in bytes | 
| [ ].number | Number | Message number | 
| [ ].id | Text | Unique ID of the message (useful if you store the message locally) | 
If the mailbox does not contain a message, an empty collection is returned.
number and ID properties
number is the number of a message in the mailbox at the time the POP3_transporter was created. The number property is not a static value in relation to any specific message and will change from session to session dependent on its relation to other messages in the mailbox at the time the session was opened. The numbers assigned to the messages are only valid during the lifetime of the POP3_transporter. At the time the POP3_transporter is deleted any message marked for deletion will be removed. When the user logs back into the server, the current messages in the mailbox will be renumbered from 1 to x.
The id however is a unique number assigned to the message when it was received by the server. This number is calculated using the time and date that the message is received and is a value assigned by your POP3 server. Unfortunately, POP3 servers do not use the id as the primary reference to their messages. Throughout the POP3 sessions you will need to specify the number as the reference to messages on the server. Developers may need to take some care if developing solutions which bring references to messages into a database but leave the body of the message on the server.
Example
You want to know the total number and size of emails in the mailbox:
 var $server : Object
 $server:=New object
 $server.host:="pop.gmail.com" //Mandatory
 $server.port:=995
 $server.user:="4d@gmail.com"
 $server.password:="XXXXXXXX"
 var $transporter : 4D.POP3Transporter
 $transporter:=POP3 New transporter($server)
 C_COLLECTION($mailInfo)
 C_LONGINT($vNum;$vSize)
 $mailInfo:=$transporter.getMailInfoList()
 $vNum:=$mailInfo.length
 $vSize:=$mailInfo.sum("size")
 ALERT("The mailbox contains "+String($vNum)+" message(s) for "+String($vSize)+" bytes.")
.getMIMEAsBlob()
History
| Release | Changes | 
|---|---|
| 18 R3 | Added | 
.getMIMEAsBlob*( msgNumber : Integer ) : Blob
| Parameter | Type | Description | |
|---|---|---|---|
| msgNumber | Integer | -> | Number of the message in the list | 
| Result | Blob | <- | Blob of the MIME string returned from the mail server | 
Description
The .getMIMEAsBlob() function returns a BLOB containing the MIME contents for the message corresponding to the msgNumber in the mailbox designated by the POP3_transporter.
In msgNumber, pass the number of the message to retrieve. This number is returned in the number property by the .getMailInfoList() method.
The method returns an empty BLOB if:
- msgNumber designates a non-existing message,
- the message was marked for deletion using .delete().
Returned BLOB
.getMIMEAsBlob() returns a BLOB which can be archived in a database or converted to an Email object with the MAIL Convert from MIME command.
Example
You want to know the total number and size of emails in the mailbox:
 var $server : Object
 var $mailInfo : Collection
 var $blob : Blob
 var $transporter : 4D.POP3Transporter
 $server:=New object
 $server.host:="pop.gmail.com"
 $server.port:=995
 $server.user:="4d@gmail.com"
 $server.password:="XXXXXXXX"
 $transporter:=POP3 New transporter($server)
 $mailInfo:=$transporter.getMailInfoList()
 $blob:=$transporter.getMIMEAsBlob($mailInfo[0].number)
.undeleteAll()
History
| Release | Changes | 
|---|---|
| 18 R2 | Added | 
*.undeleteAll()**
| Parameter | Type | Description | |
|---|---|---|---|
| Does not require any parameters | 
Description
The .undeleteAll() function removes all delete flags set on the emails in the POP3_transporter.