PTLib  Version 2.14.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
PSMTPClient Class Reference

A TCP/IP socket for the Simple Mail Transfer Protocol. More...

#include <inetmail.h>

Inheritance diagram for PSMTPClient:
Collaboration diagram for PSMTPClient:

Public Member Functions

 PSMTPClient ()
 Create a TCP/IP SMPTP protocol socket channel. More...
 
 ~PSMTPClient ()
 Destroy the channel object. More...
 
virtual PBoolean Close ()
 Close the socket, and if connected as a client, QUITs from server. More...
 
PBoolean LogIn (const PString &username, const PString &password)
 Log into the SMTP server using the mailbox and access codes specified. More...
 
PBoolean BeginMessage (const PString &from, const PString &to, PBoolean eightBitMIME=false)
 Begin transmission of a message using the SMTP socket as a client. More...
 
PBoolean BeginMessage (const PString &from, const PStringList &toList, PBoolean eightBitMIME=false)
 
PBoolean EndMessage ()
 End transmission of a message using the SMTP socket as a client. More...
 

Protected Member Functions

PBoolean OnOpen ()
 This callback is executed when the Open() function is called with open channels. More...
 
- Protected Member Functions inherited from PSMTP
 PSMTP ()
 
- Protected Member Functions inherited from PInternetProtocol
 PInternetProtocol (const char *defaultServiceName, PINDEX cmdCount, char const *const *cmdNames)
 
virtual PINDEX ParseResponse (const PString &line)
 Parse a response line string into a response code and any extra info on the line. More...
 

Protected Attributes

PBoolean haveHello
 
PBoolean extendedHello
 
PBoolean eightBitMIME
 
PString fromAddress
 
PStringList toNames
 
PBoolean sendingData
 

Additional Inherited Members

- Public Types inherited from PSMTP
enum  Commands {
  HELO, EHLO, QUIT, HELP,
  NOOP, TURN, RSET, VRFY,
  EXPN, RCPT, MAIL, SEND,
  SAML, SOML, DATA, AUTH,
  NumCommands
}
 
- Static Public Member Functions inherited from PChannel
static PString GetErrorText (Errors lastError, int osError=0)
 Get error message description. More...
 
- Static Public Member Functions inherited from PObject
static const char * Class ()
 Get the name of the class as a C string. More...
 
static __inline const PObjectPTraceObjectInstance (const char *)
 
static __inline const PObjectPTraceObjectInstance (const PObject *obj)
 
static Comparison InternalCompareObjectMemoryDirect (const PObject *obj1, const PObject *obj2, PINDEX size)
 Internal function caled from CompareObjectMemoryDirect() More...
 
- Protected Types inherited from PInternetProtocol
enum  StuffState {
  DontStuff, StuffIdle, StuffCR, StuffCRLF,
  StuffCRLFdot, StuffCRLFdotCR
}
 
- Friends inherited from PObject

Detailed Description

A TCP/IP socket for the Simple Mail Transfer Protocol.

When acting as a client, the procedure is to make the connection to a remote server, then to send a message using the following procedure: PSMTPSocket mail("mailserver"); if (mail.IsOpen()) { mail.BeginMessage("Me@here.com.au", "Fred@somwhere.com"); mail.Write(myMessage); if (!mail.EndMessage()) PError << "Mail send failed." << endl; } else PError << "Mail conection failed." << endl;

Constructor & Destructor Documentation

PSMTPClient::PSMTPClient ( )

Create a TCP/IP SMPTP protocol socket channel.

The parameterless form creates an unopened socket, the form with the address parameter makes a connection to a remote system, opening the socket. The form with the socket parameter opens the socket to an incoming call from a "listening" socket.

PSMTPClient::~PSMTPClient ( )

Destroy the channel object.

This will close the channel and as a client, QUIT from remote SMTP server.

Member Function Documentation

PBoolean PSMTPClient::BeginMessage ( const PString from,
const PString to,
PBoolean  eightBitMIME = false 
)

Begin transmission of a message using the SMTP socket as a client.

This negotiates with the remote server and establishes the protocol state for data transmission. The usual Write() or stream commands may then be used to transmit the data itself.

Returns
true if message was handled, false if an error occurs.
Parameters
fromUser name of sender.
toUser name of recipient.
eightBitMIMEMesage will be 8 bit MIME.
PBoolean PSMTPClient::BeginMessage ( const PString from,
const PStringList toList,
PBoolean  eightBitMIME = false 
)
Parameters
fromUser name of sender.
toListList of user names of recipients.
eightBitMIMEMesage will be 8 bit MIME.
virtual PBoolean PSMTPClient::Close ( )
virtual

Close the socket, and if connected as a client, QUITs from server.

Returns
true if the channel was closed and the QUIT accepted by the server.

Reimplemented from PIndirectChannel.

PBoolean PSMTPClient::EndMessage ( )

End transmission of a message using the SMTP socket as a client.

Returns
true if message was accepted by remote server, false if an error occurs.
PBoolean PSMTPClient::LogIn ( const PString username,
const PString password 
)

Log into the SMTP server using the mailbox and access codes specified.

Login is actually attempted only if the server supports SASL authentication and a common method is found

Returns
true if logged in.
Parameters
usernameUser name on remote system.
passwordPassword for user name.
PBoolean PSMTPClient::OnOpen ( )
protectedvirtual

This callback is executed when the Open() function is called with open channels.

It may be used by descendent channels to do any handshaking required by the protocol that channel embodies.

The default behaviour is to simply return true.

Returns
Returns true if the protocol handshaking is successful.

Reimplemented from PIndirectChannel.

Member Data Documentation

PBoolean PSMTPClient::eightBitMIME
protected
PBoolean PSMTPClient::extendedHello
protected
PString PSMTPClient::fromAddress
protected
PBoolean PSMTPClient::haveHello
protected
PBoolean PSMTPClient::sendingData
protected
PStringList PSMTPClient::toNames
protected

The documentation for this class was generated from the following file: