A classe TMailMng realiza a comunicação com o servidor de e-mail. Ela permite a utilização dos seguintes protocolos:
- POP
- POP + SSL
- IMAP
- IMAP + SSL
- MAPI
- SMTP
- SMTP + SSL
- SMTP + TLS
Ela vem como substituição à classe TMailManager, contendo propriedades de classe para definir e retornar os valores utilizados no programa; unificação de métodos para conexão e desconexão, fazendo com que não seja necessário utilizar métodos específicos por protocolo, causando confusão; separação de controles para recebimento e envio de emails; não possui dependência de valores definidos no arquivo ini do Application Server para seu funcionamento.
Hierarquia
- TMailMng
Construtores
Propriedades
Métodos
Observações
- O protocolo MAPI está disponível apenas em Windows
Exemplos
Exemplo 1
#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., .T., .F., SSL3, TLS10 ) conout( "Protocol: " + cValToChar( oServer:nProtocol ) ) conout( "SSL Version: " + cValToChar( oServer:nSSLVer ) ) conout( "TLS Version: " + cValToChar( oServer:nTLSVer ) ) conout( "Verbose: " + cValToChar( oServer:lVerbose ) ) conout( "Keep Message: " + cValToChar( oServer:lKeepMsg ) ) conout( "Connected: " + cValToChar( oServer:lConnected ) ) conout( "SMTP Connected: " + cValToChar( oServer:lSMTPConnected ) + CRLF ) conout( "Username: " + oServer:cUser ) conout( "Password: " + oServer:cPass + CRLF ) 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 ) 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 POP 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( "Erro 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 POP server xRet := oServer:Disconnect() If xRet <> 0 conout( "Erro Disconnect: " + oServer:GetErrorString( xRet ) ) return EndIf conout( "Connected: " + cValToChar( oServer:lConnected ) ) conout( "SMTP Connected: " + cValToChar( oServer:lSMTPConnected ) + CRLF ) // Make SMTP connection xRet := oServer:SMTPConnect() If xRet <> 0 conout( "Erro SMTP Connect: " + oServer:GetErrorString( xRet ) ) return EndIf conout( "Connected: " + cValToChar( oServer:lConnected ) ) conout( "SMTP Connected: " + cValToChar( oServer:lSMTPConnected ) + CRLF ) // Authenticate with the wrong credentials xRet := oServer:SMTPAuth( "user", "pass" ) If xRet <> 0 conout( "Erro SMTP Auth: " + oServer:GetErrorString( xRet ) + CRLF ) Endif // Authenticate with the right credentials xRet := oServer:SMTPAuth( oServer:cUser, oServer:cPass ) If xRet <> 0 conout( "Erro SMTP Auth: " + oServer:GetErrorString( xRet ) ) return Endif 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() If xRet != 0 Conout( "Erro SMTPDisconnect: " + oServer:GetErrorString( xRet ) ) Return .F. EndIf conout( "Connected: " + cValToChar( oServer:lConnected ) ) conout( "SMTP Connected: " + cValToChar( oServer:lSMTPConnected ) + CRLF ) Return
Abrangência
Disponível em builds superiores a 7.00.131227A.
Veja também
Visão Geral
Import HTML Content
Conteúdo das Ferramentas
Tarefas