POP3Transporter
The POP3Transporter
class allows you to retrieve messages from a POP3 email server.
Objeto POP3 Transporter
POP3 Transporter objects are instantiated with the POP3 New transporter command. Ofrecen las siguientes propiedades y funciones:
.acceptUnsecureConnection : Boolean True if 4D is allowed to establish an unencrypted connection |
.authenticationMode : Text the authentication mode used to open the session on the mail server |
.checkConnection() : Object checks the connection using information stored in the transporter object |
.connectionTimeOut : Integer the maximum wait time (in seconds) allowed to establish a connection to the server |
.delete( msgNumber : Integer ) flags the msgNumber email for deletion from the POP3 server |
.getBoxInfo() : Object returns a boxInfo object corresponding to the mailbox designated by the POP3 transporter |
.getMail( msgNumber : Integer { ; headerOnly : Boolean } ) : Object returns the Email object corresponding to the msgNumber in the mailbox designated by the POP3 transporter |
.getMailInfo( msgNumber : Integer ) : Object returns a mailInfo object corresponding corresponding to the msgNumber in the mailbox designated by the POP3 transporter |
.getMailInfoList() : Collection returns a collection of mailInfo objects describing all messages in the mailbox designated by the POP3 transporter |
.getMIMEAsBlob( msgNumber : Integer ) : Blob returns a BLOB containing the MIME contents for the message corresponding to the msgNumber in the mailbox designated by the POP3_transporter |
.host : Text the name or the IP address of the host server |
.logFile : Text the path of the extended log file defined (if any) for the mail connection |
.port : Integer the port number used for mail transactions |
.undeleteAll() removes all delete flags set on the emails in the POP3_transporter |
.user : Text the user name used for authentication on the mail server |
POP3 New transporter
Historia
Lanzamiento | Modificaciones |
---|---|
18 R2 | Añadidos |
POP3 New transporter( server : Object ) : 4D.POP3Transporter
Parámetros | Tipo | Descripción | |
---|---|---|---|
server | object | -> | Información del servidor de correo |
Result | 4D.POP3Transporter | <- | POP3 transporter object |
Descripción
The POP3 New transporter
command configures a new POP3 connectionaccording to the server parameter and returns a new POP3 transporter object. El objeto transportador devuelto se utilizará normalmente para recibir correos electrónicos.
In the server parameter, pass an object containing the following properties:
server | Valor por defecto (si se omite) |
---|---|
.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 SMTP transporter object. | ninguno |
.authenticationMode : Text the authentication mode used to open the session on the mail server | se utiliza el modo de autenticación más seguro soportado por el servidor |
.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 | obligatorio |
.logFile : Text the path of the extended log file defined (if any) for the mail connection | ninguno |
.password : Text User password for authentication on the server. Not returned in SMTP transporter object. | ninguno |
.port : Integer the port number used for mail transactions | 995 |
.user : Text the user name used for authentication on the mail server | ninguno |
Result
The function returns a POP3 transporter object. All returned properties are read-only.
La conexión POP3 se cierra automáticamente cuando se destruye el objeto transportador.
Ejemplo
var $server : Object
$server:=New object
$server.host:="pop.gmail.com" //Obligatorio
$server.port:=995
$server.user:="4d@gmail.com"
$server.password:="XXXXXXXX"
$server.logFile:="LogTest.txt" //log a registrar en la carpeta Logs
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
Parámetros | Tipo | Descripción | |
---|---|---|---|
server | Object | -> | Información del servidor de correo |
Result | 4D.POP3Transporter | <- | POP3 transporter object |
Descripción
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).
.acceptUnsecureConnection
Historia
Lanzamiento | Modificaciones |
---|---|
17 R4 | Añadidos |
.acceptUnsecureConnection : Boolean
Descripción
The .acceptUnsecureConnection
property contains True if 4D is allowed to establish an unencrypted connection when encrypted connection is not possible.
It contains False if unencrypted connections are unallowed, in which case an error in returned when encrypted connection is not possible.
Los puertos seguros disponibles son:
SMTP
- 465: SMTPS
- 587 o 25: SMTP con actualización STARTTLS si lo soporta el servidor.
IMAP
- 143: Puerto IMAP no encriptado
- 993: IMAP con actualización STARTTLS si lo soporta el servidor
POP3
- 110: Puerto POP3 no encriptado
- 995: POP3 con actualización STARTTLS si lo soporta el servidor.
.authenticationMode
Historia
Lanzamiento | Modificaciones |
---|---|
17 R4 | Añadidos |
.authenticationMode : Text
Descripción
The .authenticationMode
property contains the authentication mode used to open the session on the mail server.
Por defecto, se utiliza el modo más seguro soportado por el servidor.
Los valores posibles son:
Valor | Constantes | Comentario |
---|---|---|
APOP | POP3 authentication APOP | Authentication using APOP protocol (POP3 only) |
CRAM-MD5 | POP3 authentication CRAM MD5 | Autenticación utilizando el protocolo CRAM-MD5 |
LOGIN | POP3 authentication login | Autenticación utilizando el protocolo LOGIN |
OAUTH2 | POP3 authentication OAUTH2 | Autenticación utilizando el protocolo OAuth2 |
PLAIN | POP3 authentication plain | Autenticación utilizando el protocolo PLAIN |
.checkConnection()
Historia
Lanzamiento | Modificaciones |
---|---|
17 R4 | Añadidos |
.checkConnection() : Object
Parámetros | Tipo | Descripción | |
---|---|---|---|
Result | Object | <- | Estado de la conexión del objeto transportador |
Descripción
The .checkConnection()
function checks the connection using information stored in the transporter object, recreates the connection if necessary, and returns the status. Esta función permite verificar que los valores proporcionados por el usuario son válidos y coherentes.
Objeto devuelto
La función envía una solicitud al servidor de correo y devuelve un objeto que describe el estado del correo. Este objeto puede contener las siguientes propiedades:
Propiedad | Tipo | Descripción | |
---|---|---|---|
success | boolean | True si la verificación es exitosa, False en caso contrario | |
status | number | (sólo SMTP) Código de estado devuelto por el servidor de correo (0 en caso de un problema no relacionado con el procesamiento del correo) | |
statusText | text | Mensaje de estado devuelto por el servidor de correo, o último error devuelto en la pila de errores de 4D | |
errors | collection | Pila de errores 4D (no se devuelve si se recibe una respuesta del servidor de correo) | |
[ ].errCode | number | Código de error 4D | |
[ ].message | text | Descripción del error 4D | |
[ ].componentSignature | text | Firma del componente interno que ha devuelto el error |
Ejemplo
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
.connectionTimeOut
Historia
Lanzamiento | Modificaciones |
---|---|
17 R5 | Añadidos |
.connectionTimeOut : Integer
Descripción
The .connectionTimeOut
property contains the maximum wait time (in seconds) allowed to establish a connection to the server. By default, if the property has not been set in the server object (used to create the transporter object with SMTP New transporter
, POP3 New transporter
, or IMAP New transporter
), the value is 30.
.delete()
Historia
Lanzamiento | Modificaciones |
---|---|
18 R2 | Añadidos |
.delete( msgNumber : Integer )
Parámetros | Tipo | Descripción | |
---|---|---|---|
msgNumber | Integer | -> | Número del mensaje a eliminar |
Descripción
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.
La ejecución de este método no elimina realmente ningún correo electrónico. 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.
Si la sesión actual termina inesperadamente y se cierra la conexión (por ejemplo, por tiempo de espera, fallo de la red, etc.), se genera un mensaje de error y los mensajes marcados para ser borrados permanecerán en el servidor POP3.
Ejemplo
$mailInfoList:=$POP3_transporter.getMailInfoList()
For each($mailInfo;$mailInfoList)
// Marcar el correo como "a eliminar al final de la sesión"
$POP3_transporter.delete($mailInfo.number)
End for each
// Forzar el cierre de sesión para eliminar los correos marcados para ser borrados
CONFIRM("Selected messages will be deleted.";"Delete";"Undo")
If(OK=1) //borrado confirmado
$POP3_transporter:=Null
Else
$POP3_transporter.undeleteAll() //eliminar los marcadores de eliminación
End if
.getBoxInfo()
Historia
Lanzamiento | Modificaciones |
---|---|
18 R2 | Añadidos |
.getBoxInfo() : Object
Parámetros | Tipo | Descripción | |
---|---|---|---|
Result | Object | <- | objeto boxInfo |
Descripción
The .getBoxInfo()
function returns a boxInfo
object corresponding to the mailbox designated by the POP3 transporter
. Esta función permite recuperar la información sobre el buzón.
The boxInfo
object returned contains the following properties:
Propiedad | Tipo | Descripción |
---|---|---|
mailCount | Number | Número de mensajes en el buzón |
size | Number | Tamaño del mensaje en bytes |
Ejemplo
var $server; $boxinfo : Object
$server:=New object
$server.host:="pop.gmail.com" //Obligatorio
$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()
Historia
Lanzamiento | Modificaciones |
---|---|
20 | Support of headerOnly parameter |
18 R2 | Añadidos |
.getMail( msgNumber : Integer { ; headerOnly : Boolean } ) : Object
Parámetros | Tipo | Descripción | |
---|---|---|---|
msgNumber | Integer | -> | Número del mensaje en la lista |
headerOnly | Boolean | -> | True para descargar sólo los encabezados del correo electrónico (por defecto, False) |
Result | Object | <- | Email object |
Descripción
The .getMail()
function returns the Email
object corresponding to the msgNumber in the mailbox designated by the POP3 transporter
. Esta función permite recuperar la información sobre el email.
Pass in msgNumber the number of the message to retrieve. This number is returned in the number
property by the .getMailInfoList()
function.
Optionally, you can pass true
in the headerOnly parameter to exclude the body parts from the returned Email
object. Only headers properties (headers
, to
, from
...) se devuelven. Esta opción permite optimizar el paso de descarga cuando hay muchos correos electrónicos en el servidor.
The headerOnly option may not be supported by the server.
El método devuelve Null si:
- msgNumber designates a non-existing message,
- the message was marked for deletion using
.delete()
.
Objeto devuelto
.getMail()
returns an Email
object.
Ejemplo
Quiere saber el remitente del primer correo del buzón:
var $server; $transporter : Object
var $mailInfo : Collection
var $sender : Variant
$server:=New object
$server.host:="pop.gmail.com" //Obligatorio
$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()
Historia
Lanzamiento | Modificaciones |
---|---|
18 R2 | Añadidos |
.getMailInfo( msgNumber : Integer ) : Object
Parámetros | Tipo | Descripción | |
---|---|---|---|
msgNumber | Integer | -> | Número del mensaje en la lista |
Result | Object | <- | objeto mailInfo |
Descripción
The .getMailInfo()
function returns a mailInfo
object corresponding corresponding to the msgNumber in the mailbox designated by the POP3 transporter
. Esta función permite gestionar localmente la lista de mensajes localizados en el servidor de correo POP3.
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:
Propiedad | Tipo | Descripción |
---|---|---|
size | Number | Tamaño del mensaje en bytes |
id | Text | ID único del mensaje |
The method returns Null if:
- msgNumber designates a non-existing message,
- the message was marked for deletion using
.delete( )
.
Ejemplo
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()
Historia
Lanzamiento | Modificaciones |
---|---|
18 R2 | Añadidos |
.getMailInfoList() : Collection
Parámetros | Tipo | Descripción | |
---|---|---|---|
Result | Collection | <- | Collection of mailInfo objects |
Descripción
The .getMailInfoList()
function returns a collection of mailInfo
objects describing all messages in the mailbox designated by the POP3 transporter
. Esta función permite gestionar localmente la lista de mensajes localizados en el servidor de correo POP3.
Each mailInfo
object in the returned collection contains the following properties:
Propiedad | Tipo | Descripción |
---|---|---|
[ ].size | Number | Tamaño del mensaje en bytes |
[ ].number | Number | Número del mensaje |
[ ].id | Text | ID único del mensaje (útil si almacena el mensaje localmente) |
Si el buzón no contiene ningún mensaje, se devuelve una colección vacía.
Propiedades number e ID
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. Cuando el usuario vuelva a conectarse al servidor, los mensajes actuales en el buzón serán renumerados de 1 a x.
The id however is a unique number assigned to the message when it was received by the server. Este número se calcula utilizando la hora y la fecha de recepción del mensaje y es un valor asignado por su servidor POP3. 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. Los desarrolladores deben tener cierto cuidado si desarrollan soluciones que introducen referencias a los mensajes en una base de datos pero dejan el cuerpo del mensaje en el servidor.
Ejemplo
Quiere saber el número total y el tamaño de los correos electrónicos en el buzón:
var $server : Object
$server:=New object
$server.host:="pop.gmail.com" //Obligatorio
$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()
Historia
Lanzamiento | Modificaciones |
---|---|
18 R3 | Añadidos |
.getMIMEAsBlob( msgNumber : Integer ) : Blob
Parámetros | Tipo | Descripción | |
---|---|---|---|
msgNumber | Integer | -> | Número del mensaje en la lista |
Result | Blob | <- | Blob de la cadena MIME devuelta por el servidor de correo |
Descripción
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.
El método devuelve un BLOB vacío si:
- msgNumber designates a non-existing message,
- the message was marked for deletion using
.delete()
.
BLOB devuelto
.getMIMEAsBlob()
returns a BLOB
which can be archived in a database or converted to an Email
object with the MAIL Convert from MIME
command.
Ejemplo
Quiere saber el número total y el tamaño de los correos electrónicos en el buzón:
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)
.host
Historia
Lanzamiento | Modificaciones |
---|---|
17 R5 | Añadidos |
.host : Text
Descripción
The .host
property contains the name or the IP address of the host server. Se utiliza para las transacciones de correo (SMTP, POP3, IMAP).
.logFile
Historia
Lanzamiento | Modificaciones |
---|---|
17 R5 | Añadidos |
.logFile : Text
Descripción
The .logFile
property contains the path of the extended log file defined (if any) for the mail connection. Puede ser relativo (a la carpeta actual Logs) o absoluto.
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. Para más información sobre los archivos de registro extendidos, consulte:
- SMTP connections - 4DSMTPLog.txt
- POP3 connections - 4DPOP3Log.txt
- IMAP connections - 4DIMAPLog.txt
.port
Historia
Lanzamiento | Modificaciones |
---|---|
17 R4 | Añadidos |
.port : Integer
Descripción
The .port
property contains the port number used for mail transactions. By default, if the port property has not been set in the server object (used to create the transporter object with SMTP New transporter
, POP3 New transporter
, IMAP New transporter
), the port used is:
- SMTP - 587
- POP3 - 995
- IMAP - 993
.undeleteAll()
Historia
Lanzamiento | Modificaciones |
---|---|
18 R2 | Añadidos |
.undeleteAll()
Parámetros | Tipo | Descripción | |
---|---|---|---|
No requiere ningún parámetro |
Descripción
The .undeleteAll()
function removes all delete flags set on the emails in the POP3_transporter
.
.user
Historia
Lanzamiento | Modificaciones |
---|---|
17 R4 | Añadidos |
.user : Text
Descripción
The .user
property contains the user name used for authentication on the mail server.