xHarbour Reference Documentation > Class Reference (textmode) xHarbour Developers Network  

TIpClientSmtp()

Creates a new TIpClientSmtp object.

Syntax

TIpClientSmtp():new( <cUrl>, [<lTrace>] ) --> oTIpClientSmtp

Arguments

<cUrl>
This is a character string holding the URL of the mail server used to send eMails. It must be coded in this form:
   smtp://<mailAccount>:<password>@<mail.server.com>

Alternatively, a TUrl() object can be passed that is initialized with the SMTP mail server URL.

<lTrace>
This parameter defaults to .F. (false). When .T. (true) is passed, the communication with a mail server is logged into the file Sendmail<nn>.log, where <nn> is the number of the log file storing information of the internet communictaion with this object.

Return

The function returns a new TIpClientSmtp object and method :new() initializes the object.

Description

Objects of the TIpClientSmtp() class inherit from the generic internet client class TIpClient(). TIpClientSmtp objects are used to communicate with an SMTP mail server. They use the Simple Mail Transfer Protocol (SMTP, RFC0821.TXT) for sending, or writing, eMails. The address of the mail server must be provided as 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.

Once the internet connection is established (opened), eMails can be sent using the :sendMail() method, which accepts an eMail in form of a TIpMail() object.

When all eMails are sent, the internet connection must be closed with the :close() method.

Note:  methods of the TIpClientSmtp class are divided into "High level" and "Low level" methods. "High level" methods are designed to process TIpMail() objects, while "Low level" methods communicate with an SMTP server directly using commands of the SMTP protocol.

Instance variables

:nConnTimeout
Numeric timeout value in milliseconds.
:nDefaultPort
Numeric port number.

High level methods

:sendMail( <oTIpMail> ) --> lSuccess
Sends an eMail.

Low level methods

:auth( <cUserID>, <cPassword> ) --> lSuccess
Sends the AUTH LOGIN command to the SMTP server.
:authPlain( <cUserID>, <cPassword> ) --> lSuccess
Sends the AUTH PLAIN command to the SMTP server.
:data( <cData> ) --> lSuccess
Sends the DATA command to the SMTP server.
:mail( <cFrom> ) --> lSuccess
Sends the MAIL command to the SMTP server.
:quit() --> lSuccess
Sends the QUIT command to the SMTP server.
:rcpt( <cRecipient> ) --> lSuccess
Sends the RCPT command to the SMTP server.

Info

See also:TIpClientFtp(), TIpClientHttp(), TIpClientPop(), TIpMail(), TUrl()
Category: Internet functions , Object functions , xHarbour extensions
Source:tip\smtpcln.prg
LIB:lib\xhb.lib
DLL:dll\xhb.dll

Example

// The example outlines the steps and data required to send an eMail
// including file attachment to an SMTP mail server (it forwards the eMail)

   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

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe