A classe TMailMng vem como substituição à classe TMailManager, realizando a comunicação com o servidor de e-mail, e possuindo maior flexibilidade de configuração e maior suporte de protocolos.
Hierarquia
- TMailMng
Construtores
Propriedades
Métodos
Observações
A classe permite a utilização dos seguintes protocolos:
- POP
- POP + SSL
- POP + TLS
- IMAP
- IMAP + SSL
- IMAP + TLS
- 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.
Observação
O protocolo MAPI está disponível apenas em Windows.
Para uso desta classe com o GMAIL favor consultar a documentação: Application Server - Uso de e-mail com GMail
Exemplos
#define POP3 0 #define IMAP 1 #define MAPI 2 user Function mail1() Local oServer Local oMessage Local xRet Local nNumMsg := 0 oMessage := TMailMessage():New() oServer := TMailMng():New( IMAP, 3, 6 ) conout( "Protocol: " + cValToChar( oServer:nProtocol ) ) 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 SSL Version: " + cValToChar( oServer:nSrvSSL ) ) conout( "Server SSL Retry: " + cValToChar( oServer:lSrvRetrySSL ) ) 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 IMAP connection xRet := oServer:Connect() if xRet != 0 conout( "Error on Connect: " + oServer:GetErrorString( xRet ) ) return 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( "Error 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 IMAP server xRet := oServer:Disconnect() if xRet <> 0 conout( "Error on 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( "Error on 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( "Error on SMTP Auth: " + oServer:GetErrorString( xRet ) + CRLF ) endif // Authenticate with the right credentials xRet := oServer:SMTPAuth( oServer:cUser, oServer:cPass ) if xRet <> 0 conout( "Error on 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( "Error on SMTPDisconnect: " + oServer:GetErrorString( xRet ) ) return endIf conout( "Connected: " + cValToChar( oServer:lConnected ) ) conout( "SMTP Connected: " + cValToChar( oServer:lSMTPConnected ) + CRLF ) return
Abrangência
Disponível em builds iguais ou superiores a 7.00.170117A.