xHarbour Reference Documentation > Class Reference (textmode) |
Creates a new TIpMail object.
TIpMail():new( [<cMailBody>], [<cEncode>] ) --> oTIpMail
Encoding methods for eMail bodies
Name | Description |
---|---|
as-is *) | Not encoded (unchanged) |
base64 | Base64 encoded |
quoted-printable | Encoded as quoted printable. |
url | Url encoded |
urlencoded | Url encoded |
7bit | 7bit encoded |
8bit | 8bit encoded |
*)default |
Function TIpMail() returns a new TIpMail object and method :new() initializes the object.
Objects of class TIpMail are used to manage a complete eMail. The minimum data an eMail must contain are the sender address (From), the recipient address (To), a subject line (Subject) and the text of the eMail (Body). These data can be assigned to a TIpMail object with its :setBody() and :setHeader() methods.
Note: methods of the TIptMail class are divided into "High level" and "Low level" methods. "High level" methods are designed to compose an email easily, while "Low level" methods manipulate individual entries of an eMail header. You should be familiar with eMail headers when using "Low level" methods.
See also: | TIpClientPop(), TIpClientSmtp(), TUrl() |
Category: | Internet functions , Object functions , xHarbour extensions |
Source: | tip\mail.prg |
LIB: | lib\xhb.lib |
DLL: | dll\xhb.dll |
Incoming eMails
// 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
Outgoing eMails
// The example outlines the steps required for composing an eMail // and sending it to an SMTP mail server. PROCEDURE Main LOCAL oSmtp, oEMail LOCAL cSmtpUrl LOCAL cSubject, cFrom, cTo, cBody, cFile // preparing data for eMail cSmtpUrl := "smtp://mailaccount:password@smtp.server.com" cSubject := "Testing eMail" cFrom := "MyName@Mail.server.com" cTo := "YourName@another.server.com" cFile := "File_Attachment.zip" cBody := "This is a test mail sent at: " + DtoC(Date()) + " " + Time() // preparing eMail object oEMail := TIpMail():new() oEMail:setHeader( cSubject, cFrom, cTo ) oEMail:setBody( cBody ) oEMail:attachFile( cFile ) // preparing SMTP object oSmtp := TIpClientSmtp():new( cSmtpUrl ) // sending data via internet connection IF oSmtp:open() oSmtp:sendMail( oEMail ) oSmtp:close() ? "Mail sent" ELSE ? "Error:", oSmtp:lastErrorMessage() ENDIF RETURN
http://www.xHarbour.com