Permite obter o conteúdo do arquivo atachado e retornar esse conteúdo através de uma string.
Sintaxe
GetAttach( < cNumMsg > )
Parâmetros
Nome | Tipo | Descrição | Obrigatório | Referência |
|---|---|---|---|---|
cNumMsg | numérico | Indica o ID (número de identificação da mensagem) que se deseja obter informações. | X |
Retorno
Nome | Tipo | Descrição |
|---|---|---|
cRet | caractere | Retorna uma string (cadeia de caracteres) contendo o conteúdo do arquivo anexado na mensagem. |
Exemplos
Exemplo 1
user function tstGetAttach()
Local oServer
Local oMessage
Local nAttach := 0, nI := 0
Local nMessages := 0
Local cAttach := "", cName := ""
Local aAttInfo := {}
Local xRet
oServer := tMailManager():New()
writePProString( "Mail", "Protocol", "POP3", getsrvininame() )
oServer:SetUseSSL( .T. )
xRet := oServer:Init( "mail.totvs.com.br", "", "username", "password", 995, 0 )
if xRet <> 0
conout( "Could not initialize mail server: " + oServer:GetErrorString( xRet ) )
return
endif
xRet := oServer:POPConnect()
if xRet <> 0
conout( "Could not connect on POP3 server: " + oServer:GetErrorString( xRet ) )
return
endif
oServer:GetNumMsgs( @nMessages )
conout( "Number of messages: " + cValToChar( nMessages ) )
oMessage := TMailMessage():New()
oMessage:Clear()
conout( "Receiving newest message" )
xRet := oMessage:Receive( oServer, nMessages )
if xRet <> 0
conout( "Could not get message " + cValToChar( nMessages ) + ": " + oServer:GetErrorString( xRet ) )
return
endif
nAttach := oMessage:GetAttachCount()
for nI := 1 to nAttach
aAttInfo := oMessage:GetAttachInfo( nI )
cName := "\emails\"
if aAttInfo[1] == ""
cName += "message." + SubStr( aAttInfo[2], At( "/", aAttInfo[2] ) + 1, Len( aAttInfo[2] ) )
else
cName += aAttInfo[1]
endif
conout( "Saving attachment " + cValToChar( nI ) + ": " + cName )
cAttach := oMessage:GetAttach( nI )
xRet := MemoWrite( cName, cAttach )
if !xRet
conout( "Could not save attachment " + cValToChar( nI ) )
endif
next nI
xRet := oServer:POPDisconnect()
if xRet <> 0
conout( "Could not disconnect from POP3 server: " + oServer:GetErrorString( xRet ) )
endif
return
Import HTML Content
Visão Geral
Conteúdo das Ferramentas