Anexa um arquivo ao objeto de e-mail.
Sintaxe
AttachFile( < cFile >, [ nParam2 ], [ cParam3 ] )
Parâmetros
Nome | Tipo | Descrição | Obrigatório | Referência |
|---|---|---|---|---|
cFile | caractere | Indica o nome do arquivo, a partir do rootpath, a ser anexado no e-mail. | X | |
nParam2 | numérico | Parâmetro de compatiblidade. Passar Nil (nulo). | ||
cParam3 | caractere | Parâmetro de compatiblidade. Passar Nil (nulo). |
Retorno
Nome | Tipo | Descrição |
|---|---|---|
nRet | numérico | Em caso de sucesso, retorna o índice do arquivo anexado, iniciando em 0 (zero). Em caso de erro, retorna -1. |
Exemplos
Exemplo 1
user function tstAttFile()
Local cMsg := "", cFile := ""
Local cUser := "", cPass := ""
Local xRet
Local oServer, oMessage
cFile := "\temp\attach.txt"
xRet := MemoWrite( cFile, "attachment 1 e-mail" )
if !xRet
cMsg := "Could not create attachment " + cFile
conout( cMsg )
return
endif
oMessage := TMailMessage():New()
oMessage:Clear()
oMessage:cDate := cValToChar( Date() )
oMessage:cFrom := "[email protected]"
oMessage:cTo := "[email protected]"
oMessage:cSubject := "Test"
oMessage:cBody := "Email Test"
xRet := oMessage:AttachFile( cFile )
if xRet < 0
cMsg := "Could not attach file " + cFile
conout( cMsg )
return
endif
oServer := tMailManager():New()
oServer:SetUseTLS( .T. )
cUser := "username"
cPass := "password"
xRet := oServer:Init( "", "mail.totvs.com.br", cUser, cPass, 0, 587 )
if xRet != 0
cMsg := "Could not initialize SMTP server: " + oServer:GetErrorString( xRet )
conout( cMsg )
return
endif
xRet := oServer:SetSMTPTimeout( 60 )
if xRet != 0
cMsg := "Could not set " + cProtocol + " timeout to " + cValToChar( nTimeout )
conout( cMsg )
endif
xRet := oServer:SMTPConnect()
if xRet <> 0
cMsg := "Could not connect on SMTP server: " + oServer:GetErrorString( xRet )
conout( cMsg )
return
endif
xRet := oServer:SmtpAuth( cUser, cPass )
if xRet <> 0
cMsg := "Could not authenticate on SMTP server: " + oServer:GetErrorString( xRet )
conout( cMsg )
oServer:SMTPDisconnect()
return
endif
xRet := oMessage:Send( oServer )
if xRet <> 0
cMsg := "Could not send message: " + oServer:GetErrorString( xRet )
conout( cMsg )
endif
xRet := oServer:SMTPDisconnect()
if xRet <> 0
cMsg := "Could not disconnect from SMTP server: " + oServer:GetErrorString( xRet )
conout( cMsg )
endif
return
Import HTML Content
Visão Geral
Conteúdo das Ferramentas