Permite definir um header ao último arquivo anexado na mensagem a ser enviada.
Sintaxe
numérico AddAttHTag( < cTag > )
Parâmetros
Nome | Tipo | Descrição | Obrigatório | Referência |
---|
cTag | caractere | Indica os dados que se deseja informar para o último arquivo anexado. | X | |
Retorno
Nome | Tipo | Descrição |
---|
nRet | numérico | Retorna o índice do header adicionado na lista caso existe algum anexo. Caso não tenha anexos, retorna -1. |
Exemplos
user function tstAddHTag()
Local cMsg := "", cContent := ""
Local cUser := "", cPass := ""
Local xRet
Local oServer, oMessage
cContent := "attachment 1 email"
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:Attach( cContent, "", 0 )
if xRet < 0
cMsg := "Could not attach file " + cFile
conout( cMsg )
return
endif
oMessage:AddAttHTag( "Content-Disposition: attachment; filename=attach.txt" )
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