Saltar para o conteúdo principal
Versão: 20 R5 BETA

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. Eles oferecem as propriedades abaixo e funções:

.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

História
ReleaseMudanças
18 R2Adicionado

POP3 New transporter( server : Object ) : 4D.POP3Transporter

ParâmetroTipoDescrição
serverobject->Informação de servidor de correio
Resultados4D.POP3Transporter<-POP3 transporter object

Descrição

The POP3 New transporter command configures a new POP3 connectionaccording to the server parameter and returns a new POP3 transporter object. O objeto transporter retornado vai geralmente ser usado para receber emails.

In the server parameter, pass an object containing the following properties:

serverValor padrão (se omitido)
.acceptUnsecureConnection : Boolean&nbsp;&nbsp;&nbsp;&nbsp;True 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 SMTP transporter object.
nenhum
.authenticationMode : Text&nbsp;&nbsp;&nbsp;&nbsp;the authentication mode used to open the session on the mail servero modo de autenticação mais seguro disponível no servidor é usado
.connectionTimeOut : Integer&nbsp;&nbsp;&nbsp;&nbsp;the maximum wait time (in seconds) allowed to establish a connection to the server30
.host : Text&nbsp;&nbsp;&nbsp;&nbsp;the name or the IP address of the host servermandatory
.logFile : Text&nbsp;&nbsp;&nbsp;&nbsp;the path of the extended log file defined (if any) for the mail connectionnenhum
.password : Text
User password for authentication on the server. Not returned in SMTP transporter object.
nenhum
.port : Integer&nbsp;&nbsp;&nbsp;&nbsp; the port number used for mail transactions995
.user : Text&nbsp;&nbsp;&nbsp;&nbsp; the user name used for authentication on the mail servernenhum

Resultados

The function returns a POP3 transporter object. All returned properties are read-only.

A conexão POP3 é fechada automaticamente quando o objeto transportador for destruído.

Exemplo

 var $server : Object
$server:=New object
$server.host:="pop.gmail.com" //Obrigatório
$server.port:=995
$server.user:="4d@gmail.com"
$server.password:="XXXXXXXX"
$server.logFile:="LogTest.txt" //histórico para salvar na pasta 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âmetroTipoDescrição
serverObject->Informação de servidor de correio
Resultados4D.POP3Transporter<-POP3 transporter object

Descrição

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

História
ReleaseMudanças
17 R4Adicionado

.acceptUnsecureConnection : Boolean

Descrição

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.

Estão disponíveis portos seguros:

  • SMTP

    • 465: SMTPS
    • 587 ou 25: SMTP com atualização STARTTLS se for compat[ivel com o servidor.
  • IMAP

    • 143: IMAP non-encrypted port
    • 993: IMAP com atualização STARTTLS se for compatível com o servidor
  • POP3

    • 110: Porta não criptografada POP3
    • 995: POP3 com atualização STARTTLS se suportado pelo servidor.

.authenticationMode

História
ReleaseMudanças
17 R4Adicionado

.authenticationMode : Text

Descrição

The .authenticationMode property contains the authentication mode used to open the session on the mail server.

Por padrão, o modo mais seguro suportado pelo servidor é usado.

Valores possíveis:

ValorConstantesComentário
APOPAutenticação POP3 APOPAutenticação usando o protocolo APOP (POP3 apenas)
CRAM-MD5POP3 authentication CRAM MD5Autenticação usando o protocolo CRAM-MD5
LOGINPOP3 authentication loginAutenticação usando o protocolo LOGIN
OAUTH2POP3 authentication OAUTH2Autenticação usando o protocolo OAuth2
PLAINAutenticação POP3 simplesAutenticação usando o protocolo PLAIN

.checkConnection()

História
ReleaseMudanças
17 R4Adicionado

.checkConnection() : Object

ParâmetroTipoDescrição
ResultadosObject<-Estado da ligação do objecto transportador

Descrição

The .checkConnection() function checks the connection using information stored in the transporter object, recreates the connection if necessary, and returns the status. Esta função permite verificar se os valores fornecidos pelo utilizador são válidos e consistentes.

Objeto devolvido

A função envia um pedido para o servidor de correio e devolve um objecto descrevendo o estado do correio. Este objeto pode conter as seguintes propriedades:

PropriedadeTipoDescrição
successbooleanVerdadeiro se a verificação for bem sucedida, Falso de outra forma
statusnumber(apenas SMTP) Código de estado devolvido pelo servidor de correio (0 no caso de um problema não relacionado com o processamento de correio)
statusTexttextMensagem de estado devolvida pelo servidor de correio, ou último erro devolvido na pilha de erros 4D
errorscollectionpilha de erros 4D (não devolvida se for recebida uma resposta do servidor de correio)
[ ].errCodenumberCódigo de erro 4D
[ ].messagetextDescrição do erro 4D
[ ].componentSignaturetextAssinatura da componente interna que devolveu o erro

Exemplo

 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

História
ReleaseMudanças
17 R5Adicionado

.connectionTimeOut : Integer

Descrição

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()

História
ReleaseMudanças
18 R2Adicionado

.delete( msgNumber : Integer )

ParâmetroTipoDescrição
msgNumberInteger->Número da mensagem que vai ser apagada
Descrição

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.

Executar esse método não remove de verdade qualquer 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.

Se a sessão atual terminar de forma inesperada e perder a conexão (por exemplo timeout, falha de rede, etc), uma mensagem de erro é gerada e mensagens marcadas para serem apagadas continuam no servidor POP3.

Exemplo
 $mailInfoList:=$POP3_transporter.getMailInfoList()
For each($mailInfo;$mailInfoList)
// Marca seu email a "to be deleted at the end of the session"
$POP3_transporter.delete($mailInfo.number)
End for each
// Força que o fechamento da sessão apague os emails marcados para serem eliminados
CONFIRM("Selected messages will be deleted.";"Delete";"Undo")
If(OK=1) //eliminação confirmada
$POP3_transporter:=Null
Else
$POP3_transporter.undeleteAll() //remove marcas de eliiminação
End if

.getBoxInfo()

História
ReleaseMudanças
18 R2Adicionado

.getBoxInfo() : Object

ParâmetroTipoDescrição
ResultadosObject<-objecto boxInfo
Descrição

The .getBoxInfo() function returns a boxInfo object corresponding to the mailbox designated by the POP3 transporter. Essa função permite que recupere informação sobre o mailbox.

The boxInfo object returned contains the following properties:

PropriedadeTipoDescrição
mailCountNumberNúmero de mensagens na caixa de email
sizeNumberTamanho da mensagem em bytes
Exemplo
 var $server; $boxinfo : Object

$server:=New object
$server.host:="pop.gmail.com" //Obrigatório
$server.port:=995
$server.user:="4d@gmail.com"
$server.password:="XXXXXXXX"

$transporter:=POP3 New transporter($server)

//mailbox informação
$boxInfo:=$transporter.getBoxInfo()
ALERT("The mailbox contains "+String($boxInfo.mailCount)+" messages.")

.getMail()

História
ReleaseMudanças
20Support of headerOnly parameter
18 R2Adicionado

.getMail( msgNumber : Integer { ; headerOnly : Boolean } ) : Object

ParâmetroTipoDescrição
msgNumberInteger->Número da mensagem que na lista
headerOnlyParâmetros->True para descarregar apenas os cabeçalhos de correio electrónico (por defeito é False)
ResultadosObject<-Email object
Descrição

The .getMail() function returns the Email object corresponding to the msgNumber in the mailbox designated by the POP3 transporter. Essa função permite manejar localmente os conteúdos de 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...) are then returned. Esta opção permite-lhe optimizar a etapa de descarregamento quando muitos e-mails estão no servidor.

nota

The headerOnly option may not be supported by the server.

O método retorna Null se:

  • msgNumber designates a non-existing message,
  • the message was marked for deletion using .delete().

Returned object

.getMail() returns an Email object.

Exemplo

Se quiser saber o emissário do primeiro email da mailbox:

 var $server; $transporter : Object
var $mailInfo : Collection
var $sender : Variant

$server:=New object
$server.host:="pop.gmail.com" //Obrigatório
$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()

História
ReleaseMudanças
18 R2Adicionado

.getMailInfo( msgNumber : Integer ) : Object

ParâmetroTipoDescrição
msgNumberInteger->Número da mensagem que na lista
ResultadosObject<-mailInfo object
Descrição

The .getMailInfo() function returns a mailInfo object corresponding corresponding to the msgNumber in the mailbox designated by the POP3 transporter. Essa função permite que recupere informação sobre o 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:

PropriedadeTipoDescrição
sizeNumberTamanho da mensagem em bytes
idTextID única da mensagem

The method returns Null if:

  • msgNumber designates a non-existing message,
  • the message was marked for deletion using .delete( ).
Exemplo
 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()

História
ReleaseMudanças
18 R2Adicionado

.getMailInfoList() : Collection

ParâmetroTipoDescrição
ResultadosCollection<-Collection of mailInfo objects
Descrição

The .getMailInfoList() function returns a collection of mailInfo objects describing all messages in the mailbox designated by the POP3 transporter. Essa função permite gerenciar localmente a lista de mensagens localizadas no servidor POP3.

Each mailInfo object in the returned collection contains the following properties:

PropriedadeTipoDescrição
[ ].sizeNumberTamanho da mensagem em bytes
[ ].numberNumberNúmero da mensagem
[ ].idTextID único da mensagem (útil se armazenar a mensagem localmente)

Se a mailbox não conter uma mensagem, uma coleção vazia é retornada.

número e propriedades 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. Quando o usuário se registrar de volta no servidor, as mensagens atuais no mailbox serão numeradas de 1 a x.

The id however is a unique number assigned to the message when it was received by the server. Esse número é calculado usando a hora e data que a mensagem for recebida e é um valor atribuído ao seu 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. Desenvolvedores podem precisar ter cuirdado se desenvolverem soluções que trazem referências às mensagens na database mas deixam o corpo da mensagem no servidor.

Exemplo

Se quiser saber o número total e tamanho dos emails nas mailbox:

 var $server : Object
$server:=New object
$server.host:="pop.gmail.com" //Obrigatório
$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()

História
ReleaseMudanças
18 R3Adicionado

.getMIMEAsBlob( msgNumber : Integer ) : Blob

ParâmetroTipoDescrição
msgNumberInteger->Número da mensagem que na lista
ResultadosBlob<-Blob da string MIME retornado do servidor mail
Descrição

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.

O método retorna uma BLOB vazia se:

  • msgNumber designates a non-existing message,
  • the message was marked for deletion using .delete().

BLOB devolvido

.getMIMEAsBlob() returns a BLOB which can be archived in a database or converted to an Email object with the MAIL Convert from MIME command.

Exemplo

Se quiser saber o número total e tamanho dos emails nas 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)

.host

História
ReleaseMudanças
17 R5Adicionado

.host : Text

Descrição

The .host property contains the name or the IP address of the host server. Utilizado para transacções postais (SMTP, POP3, IMAP).

.logFile

História
ReleaseMudanças
17 R5Adicionado

.logFile : Text

Descrição

The .logFile property contains the path of the extended log file defined (if any) for the mail connection. Pode ser relativo (à pasta atual de Logs) ou 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 mais informações sobre arquivos de registo estendidos, consultar:

.port

História
ReleaseMudanças
17 R4Adicionado

.port : Integer

Descrição

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()

História
ReleaseMudanças
18 R2Adicionado

.undeleteAll()

ParâmetroTipoDescrição
Não exige nenhum parâmetro
Descrição

The .undeleteAll() function removes all delete flags set on the emails in the POP3_transporter.

.user

História
ReleaseMudanças
17 R4Adicionado

.user : Text

Descrição

The .user property contains the user name used for authentication on the mail server.