Method MIMEContent():encodeBase64() Professional
Create a MIMEContent object from a binary character string.
:encodeBase64( <cContent>, <cContentType> ) --> oMIMEContent
The class method :encodeBase64() returns an instance of the class MIMEContent.
The class method :encodeBase64() can be used to create an object of the class MIMEContent. Hereby, the content is passed as the first parameter and will be automatically base64-encoded.
The content-type that is passed as the second parameter can be used to specify the type of contents. After sending the content via e-mail for example, this information can be used to determine by which application the content can be displayed.
A common usage pattern for method :encodeBase64() is to overload MIMEMessage in order to attach all files base64-encoded:
#include "fileio.ch"
#include "asinet.ch"
// Implement overloaded MimeMessage class
CLASS MyMIMEMessage FROM MIMEMessage
EXPORTED
METHOD attachFile
ENDCLASS
//
// Overload method :attachFile().
// This implementation always encodes using base64.
// Alos, this method accepts the encoding-type.
//
METHOD MyMIMEMessage:attachFile( cFileName, cType )
LOCAL nH, nBytes, nLen, cBuffer
// Read the file if possible
IF ! FILE( cFileName )
RETURN .F.
ENDIF
// Load the file
nH := FOpen( cFileName )
IF 0 != FError()
RETURN .F.
ENDIF
// Request buffer of required size
nBytes := FSize( nH )
cBuffer := Space( nBytes )
// Read the file
nLen := FRead( nH, @cBuffer, nBytes )
// Close File
FClose( nH )
IF nLen != nBytes
RETURN .F.
ENDIF
// Attach buffer contents mixed
::MIMEContent:attachMixed( MIMEContent():encodeBase64( cBuffer, ;
cType ) )
RETURN .T.
//
// Usage of class derived from MIMEMessage
//
PROCEDUR main()
LOCAL oMime
oMime := MyMIMEMessage():new()
oMime:setMessage( "Hallo" )
// attach file with own method that encodes solely base64
oMime:attachFile( "project.xpj", "text/plain" )
RETURN
If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.