#define POP3 0
#define IMAP 1
#define MAPI 2
#define SSL2 1
#define SSL23 2
#define SSL3 3
#define TLS10 1
#define TLS11 2
#define TLS12 3
user Function mail1()
Local oServer
Local oMessage
Local xRet
Local nNumMsg := 0
oMessage := TMailMessage():New()
oServer := TMailMng():New( IMAP, .T.3, .T., .F., SSL3, TLS10 6 )
conout( "Protocol: " + cValToChar( oServer:nProtocol ) )
conout( " SSL VersionVerbose: " + cValToChar( oServer: nSSLVerlVerbose ) )
conout( " TLSKeep VersionMessage: " + cValToChar( oServer: nTLSVerlKeepMsg ) )
conout( " VerboseConnected: " + cValToChar( oServer: lVerboselConnected ) )
conout( " KeepSMTP MessageConnected: " + cValToChar( oServer: lKeepMsglSMTPConnected ) + CRLF )
conout( " ConnectedUsername: " + cValToChar( oServer: lConnectedcUser ) )
conout( " SMTP ConnectedPassword: " + cValToChar( oServer: lSMTPConnectedcPass ) + CRLF )
conout( " UsernameServer SSL Version: " + cValToChar( oServer: cUsernSrvSSL ) )
conout( " PasswordServer SSL Retry: " + cValToChar( oServer: cPasslSrvRetrySSL + CRLF) )
conout( "Server Address: " + oServer:cSrvAddr )
conout( "Server Port: " + cValToChar( oServer:nSrvPort ) )
conout( "Server Timeout: " + cValToChar( oServer:nSrvTimeout ) + CRLF )
conout( "SMTP SSL Version: " + cValToChar( oServer:nSMTPSSL ) )
conout( "SMTP SSL Retry: " + cValToChar( oServer:lSMTPRetrySSL ) )
conout( "SMTP Address: " + cValToChar( oServer:cSMTPAddr ) )
conout( "SMTP Port: " + cValToChar( oServer:nSMTPPort ) )
conout( "SMTP Timeout: " + cValToChar( oServer:nSMTPTimeout ) + CRLF )
conout( "SMTP Localhost: " + oServer:cSMTPLocalhost )
conout( "Auth Login: " + cValToChar( oServer:lAuthLogin ) )
conout( "Auth NTLM: " + cValToChar( oServer:lAuthNTLM ) )
conout( "Auth Plain: " + cValToChar( oServer:lAuthPlain ) )
conout( "Extend SMTP: " + cValToChar( oServer:lExtendSMTP ) + CRLF )
oServer:cUser := "totvsuser"
oServer:cPass := "totvspassword"
oServer:cSrvAddr := "mail.totvs.com.br"
oServer:cSMTPAddr := "mail.totvs.com.br"
conout( "Server Address: " + oServer:cSrvAddr )
conout( "Server Port: " + cValToChar( oServer:nSrvPort ) )
conout( "Server Timeout: " + cValToChar( oServer:nSrvTimeout ) + CRLF )
conout( "SMTP Address: " + cValToChar( oServer:cSMTPAddr ) )
conout( "SMTP Port: " + cValToChar( oServer:nSMTPPort ) )
conout( "SMTP Timeout: " + cValToChar( oServer:nSMTPTimeout ) + CRLF )
// Make POPIMAP connection
xRet := oServer:Connect()
if xRet != 0
conout( "Error on Connect: " + oServer:GetErrorString( xRet ) )
return .F.
endif
conout( "Connected: " + cValToChar( oServer:lConnected ) )
conout( "SMTP Connected: " + cValToChar( oServer:lSMTPConnected ) + CRLF )
// Get number of messages
xRet := oServer:GetNumMsgs( @nNumMsg )
if xRet <> 0
conout( "Error on GetNumMsgs: " + oServer:GetErrorString( xRet ) )
oServer:Disconnect()
return
endif
conout( "Number of messages: " + cValToChar( nNumMsg ) + CRLF )
if nNumMsg > 0
conout( "Receiving message 1" )
// Receives the first message
xRet := oMessage:Receive2( oServer, 1 )
if xRet != 0
conout( " ErroError on Receive2: " + oServer:GetErrorString( xRet ) )
oServer:Disconnect()
return
endif
conout( "Message 1 received!" )
conout( "From: " + oMessage:cFrom )
conout( "To: " + oMessage:cTo )
conout( "Date: " + oMessage:cDate )
conout( "Subject: " + oMessage:cSubject )
conout( "Body: " + oMessage:cBody )
conout( "Number of attachments: " + cValToChar( oMessage:GetAttachCount() ) + CRLF )
endif
// Disconnect from POPIMAP server
xRet := oServer:Disconnect()
Ifif xRet <> 0
conout( " ErroError on Disconnect: " + oServer:GetErrorString( xRet ) )
return
EndIfendIf
conout( "Connected: " + cValToChar( oServer:lConnected ) )
conout( "SMTP Connected: " + cValToChar( oServer:lSMTPConnected ) + CRLF )
// Make SMTP connection
xRet := oServer:SMTPConnect()
Ifif xRet <> 0
conout( " ErroError on SMTP Connect: " + oServer:GetErrorString( xRet ) )
return
EndIfendIf
conout( "Connected: " + cValToChar( oServer:lConnected ) )
conout( "SMTP Connected: " + cValToChar( oServer:lSMTPConnected ) + CRLF )
// Authenticate with the wrong credentials
xRet := oServer:SMTPAuth( "user", "pass" )
Ifif xRet <> 0
conout( " ErroError on SMTP Auth: " + oServer:GetErrorString( xRet ) + CRLF )
Endifendif
// Authenticate with the right credentials
xRet := oServer:SMTPAuth( oServer:cUser, oServer:cPass )
Ifif xRet <> 0
conout( " ErroError on SMTP Auth: " + oServer:GetErrorString( xRet ) )
return
Endifendif
conout( "Authentication OK!" )
// Compose a message
oMessage:Clear()
oMessage:cFrom := oServer:cUser + "@totvs.com.br"
oMessage:cTo := oMessage:cFrom
oMessage:cDate := cValToChar( Date() )
oMessage:cSubject := "New Mail Class Test"
oMessage:cBody := "Email sent with TMailMng, the new AdvPL e-mail class"
// Send the message with the new class
xRet:= oMessage:Send2( oServer )
if xRet <> 0
conout( "Error on Send2: " + oServer:GetErrorString( xRet ) )
endif
// Disconnectfrom the SMTP server
xRet := oServer:SMTPDisconnect()
Ifif xRet != 0
Conoutconout( " ErroError on SMTPDisconnect: " + oServer:GetErrorString( xRet ) )
Return .F.return
EndIfendIf
conout( "Connected: " + cValToChar( oServer:lConnected ) )
conout( "SMTP Connected: " + cValToChar( oServer:lSMTPConnected ) + CRLF )
Returnreturn
|