TMailMessage():New()
oMessage:Clear()
oMessage:cDate := cValToChar( Date() )
oMessage:cFrom := "[email protected]"
oMessage:cTo := "[email protected]"
oMessage:cSubject := "Test"
oMessage:cBody := "Email Test"
oMessage:AddCustomHeader( "X-Teste", "X-VALUE" )
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
|