| xHarbour Reference Documentation > Class Reference (textmode) |
![]() |
![]() |
![]() |
Creates a new TIpClientPop object.
TIpClientPop():new( <cUrl>, [<lTrace>] ) --> oTIpClientPop
pop3://<mailAccount>:<password>@<mail.server.com>
Alternatively, a TUrl() object can be passed that is initialized with the mail server URL.
The function returns a new TIpClientPop object and method :new() initializes the object.
Objects of the TIpClientPop() class inherit from the generic internet client class TIpClient(). TIpClientPop objects are used to communicate with a POP3 mail server. They use the Post Office Protocol (POP) for downloading, or reading, eMails. The address of the mail server must be provided with a URL string with method :new(). The URL is maintained by a TUrl() object, which is stored in the :oUrl instance variable.
The internet connection to the mail server must be established with the :open() method, after which a list of pending eMails can be queried from the mail server with the :list() method.
Individual eMails can then be retrieved with :retrieve(). This method returns the entire contents of a single eMail as a character string which can be decoded using a TIpMail() object and its :fromString() method.
Once an eMail is retrieved and stored locally, it can be deleted from the mail server using the :delete() method. If a mail is retrieved but not deleted, it remains on the mail server and can be retrieved again.
When all eMails are read, the internet connection must be closed with the :close() method.
| See also: | TIpClient(), TIpMail(), TUrl() |
| Category: | Internet functions , Object functions , xHarbour extensions |
| Source: | tip\popcln.prg |
| LIB: | lib\xhb.lib |
| DLL: | dll\xhb.dll |
// The example outlines the steps required for retrieving all
// eMails from a POP mail server and how to decompose
// incoming mail messages.
PROCEDURE Main
LOCAL oPop, oPart, aParts, oTIpMail, aEmails, i
oPop := TIpClientPop():new( "pop://mailaccount:password@pop.server.com" )
IF .NOT. oPop:open()
? "Connection error:", oPop:lastErrorMessage()
QUIT
ELSE
aEMails := oPop:retrieveAll()
oPop:close()
ENDIF
FOR i:=1 TO Len( aEMails )
oTIpMail := aEmails[i]
? oTIpMail:getFieldPart( "From" )
? oTIpMail:getFieldPart( "Subject" )
IF oTIpMail:isMultiPart()
// Retrieve all parts of a multipart message
aParts := oTIpMail:getMultiParts()
FOR EACH oPart IN aParts
IF .NOT. Empty( oPart:getFileName() )
// This is a file attachment. Store it in the TMP folder.
IF oPart:detachFile( "C:\tmp\" )
? "File written: C:\tmp\" + oPart:getFileName()
ENDIF
ELSE
? oPart:getBody()
ENDIF
NEXT
ELSE
// simple mail message
? oTIpMail:getBody()
ENDIF
NEXT
RETURN
http://www.xHarbour.com