E-MailRelay
Classes | Public Member Functions | Protected Member Functions | List of all members
GSmtp::Client Class Reference

A class which acts as an SMTP client, extracting messages from a message store and forwarding them to a remote SMTP server. More...

#include <gsmtpclient.h>

+ Inheritance diagram for GSmtp::Client:

Classes

struct  Config
 A structure containing GSmtp::Client configuration parameters. More...
 

Public Member Functions

 Client (const GNet::Location &remote, const GAuth::Secrets &secrets, Config config)
 Constructor. More...
 
virtual ~Client ()
 Destructor.
 
void sendMessagesFrom (MessageStore &store)
 Sends all messages from the given message store once connected. More...
 
void sendMessage (unique_ptr< StoredMessage > message)
 Starts sending the given message. More...
 
G::Slot::Signal1< std::string > & messageDoneSignal ()
 Returns a signal that indicates that sendMessage() has completed or failed. More...
 
- Public Member Functions inherited from GNet::Client
 Client (const Location &remote_info, unsigned int connection_timeout=0U, unsigned int response_timeout=0U, unsigned int secure_connection_timeout=0U, LineBufferConfig=LineBufferConfig(), bool bind_local_address=false, const Address &local_address=Address::defaultAddress(), bool sync_dns=synchronousDnsDefault())
 Constructor. The connection is initiated asynchronously.
 
G::Slot::Signal1< std::string > & doneSignal ()
 Returns a signal that indicates that client processing is complete. More...
 
G::Slot::Signal2< std::string, std::string > & eventSignal ()
 Returns a signal that indicates that something interesting has happened. More...
 
G::Slot::Signal0 & connectedSignal ()
 Returns a signal that indicates that the client has successfully connected to the server. More...
 
- Public Member Functions inherited from GNet::HeapClient
 HeapClient (const Location &remote_info, bool bind_local_address=false, const Address &local_address=Address::defaultAddress(), bool sync_dns=synchronousDnsDefault(), unsigned int secure_connection_timeout=0U)
 Constructor. More...
 
void doDelete (const std::string &reason)
 Calls onDelete() and then does a delayed "delete this".
 
- Public Member Functions inherited from GNet::SimpleClient
 SimpleClient (ExceptionHandler &, const Location &remote_info, bool bind_local_address=false, const Address &local_address=Address::defaultAddress(), bool sync_dns=synchronousDnsDefault(), unsigned int secure_connection_timeout=0U)
 Constructor. Call connect() to start connecting.
 
void connect ()
 Initates a connection to the remote server. More...
 
bool connected () const
 Returns true if connected to the peer.
 
virtual std::pair< bool, Address > localAddress () const override
 Override from Connection. More...
 
virtual std::pair< bool, Address > peerAddress () const override
 Override from Connection. More...
 
virtual std::string connectionState () const override
 Returns the connection state display string. More...
 
virtual std::string peerCertificate () const override
 Returns the peer's TLS certificate. More...
 
Location remoteLocation () const
 Returns a Location structure containing the result of host() and service() name lookup if available. More...
 
void updateLocation (const Location &)
 Updates the constructor's Location object with the given one as long as both objects have the same host and service name. More...
 
virtual void readEvent () override
 Override from GNet::EventHandler.
 
virtual void writeEvent () override
 Override from GNet::EventHandler.
 
virtual void otherEvent (EventHandler::Reason) override
 Override from GNet::EventHandler.
 
bool send (const std::string &data, std::string::size_type offset=0)
 Sends data to the peer. More...
 
- Public Member Functions inherited from GNet::EventHandler
virtual ~EventHandler ()
 Destructor.
 
- Public Member Functions inherited from GNet::Connection
virtual ~Connection ()
 Destructor.
 

Protected Member Functions

virtual void onConnect () override
 Override from GNet::SimpleClient.
 
virtual bool onReceive (const char *, size_t, size_t) override
 Override from GNet::Client.
 
virtual void onDelete (const std::string &) override
 Override from GNet::HeapClient.
 
virtual void onSendComplete () override
 Override from GNet::BufferedClient.
 
virtual void onSecure (const std::string &) override
 Override from GNet::SocketProtocol.
 
- Protected Member Functions inherited from GNet::Client
void clearInput ()
 Clears the line buffer. More...
 
std::string lineBufferEndOfLine () const
 Returns the line buffer end-of-line string. More...
 
virtual void onDeleteImp (const std::string &reason) override
 Override from GNet::HeapClient.
 
virtual void onConnectImp () override
 Override from GNet::SimpleClient.
 
virtual void onData (const char *, SimpleClient::size_type) override
 Override from GNet::SocketProtocolSink.
 
virtual void onConnecting () override
 Override from GNet::HeapClient.
 
virtual void onSendImp () override
 Override from GNet::SimpleClient.
 
- Protected Member Functions inherited from GNet::HeapClient
virtual ~HeapClient ()
 Destructor.
 
void finish ()
 Indicates that the last data has been sent and the client is expecting a peer disconnect. More...
 
virtual void onException (std::exception &) g__final override
 Override from GNet::ExceptionHandler. More...
 
- Protected Member Functions inherited from GNet::ExceptionHandler
virtual ~ExceptionHandler ()
 Destructor.
 
- Protected Member Functions inherited from GNet::SimpleClient
virtual ~SimpleClient ()
 Destructor.
 
StreamSocket & socket ()
 Returns a reference to the socket. Throws if not connected.
 
const StreamSocket & socket () const
 Returns a const reference to the socket. Throws if not connected.
 
void secureConnect ()
 Starts TLS/SSL client-side negotiation. More...
 
std::string logId () const
 Returns a identification string for logging purposes. More...
 
 SimpleClient (ExceptionHandler &, const Location &remote_info, bool bind_local_address=false, const Address &local_address=Address::defaultAddress(), bool sync_dns=synchronousDnsDefault(), unsigned int secure_connection_timeout=0U)
 Constructor. Call connect() to start connecting.
 
void connect ()
 Initates a connection to the remote server. More...
 
bool connected () const
 Returns true if connected to the peer.
 
virtual std::pair< bool, Address > localAddress () const override
 Override from Connection. More...
 
virtual std::pair< bool, Address > peerAddress () const override
 Override from Connection. More...
 
virtual std::string connectionState () const override
 Returns the connection state display string. More...
 
virtual std::string peerCertificate () const override
 Returns the peer's TLS certificate. More...
 
Location remoteLocation () const
 Returns a Location structure containing the result of host() and service() name lookup if available. More...
 
void updateLocation (const Location &)
 Updates the constructor's Location object with the given one as long as both objects have the same host and service name. More...
 
virtual void readEvent () override
 Override from GNet::EventHandler.
 
virtual void writeEvent () override
 Override from GNet::EventHandler.
 
virtual void otherEvent (EventHandler::Reason) override
 Override from GNet::EventHandler.
 
bool send (const std::string &data, std::string::size_type offset=0)
 Sends data to the peer. More...
 
- Protected Member Functions inherited from GNet::EventHandler
virtual ~EventHandler ()
 Destructor.
 
- Protected Member Functions inherited from GNet::Connection
virtual ~Connection ()
 Destructor.
 

Additional Inherited Members

- Public Types inherited from GNet::SimpleClient
enum  ConnectStatus { Success, Failure, ImmediateSuccess }
 
enum  State {
  Idle, Resolving, Connecting, Connected,
  Socksing, Testing
}
 
typedef std::string::size_type size_type
 
- Public Types inherited from GNet::EventHandler
enum  Reason {
  reason_closed, reason_down, reason_reset, reason_abort,
  reason_other
}
 
- Static Public Member Functions inherited from GNet::SimpleClient
static bool synchronousDnsDefault ()
 Returns true if DNS queries should normally be synchronous on this platform. More...
 
- Static Public Member Functions inherited from GNet::EventHandler
static std::string str (Reason)
 Returns a printable description of the other-event reason. More...
 
- Protected Types inherited from GNet::SimpleClient
enum  ConnectStatus { Success, Failure, ImmediateSuccess }
 
enum  State {
  Idle, Resolving, Connecting, Connected,
  Socksing, Testing
}
 
typedef std::string::size_type size_type
 
- Protected Types inherited from GNet::EventHandler
enum  Reason {
  reason_closed, reason_down, reason_reset, reason_abort,
  reason_other
}
 
- Static Protected Member Functions inherited from GNet::SimpleClient
static bool connectError (const std::string &reason)
 Returns true if the reason string implies the SimpleClient::connect() failed. More...
 
static bool synchronousDnsDefault ()
 Returns true if DNS queries should normally be synchronous on this platform. More...
 
- Static Protected Member Functions inherited from GNet::EventHandler
static std::string str (Reason)
 Returns a printable description of the other-event reason. More...
 

Detailed Description

A class which acts as an SMTP client, extracting messages from a message store and forwarding them to a remote SMTP server.

Definition at line 52 of file gsmtpclient.h.

Constructor & Destructor Documentation

GSmtp::Client::Client ( const GNet::Location &  remote,
const GAuth::Secrets &  secrets,
Config  config 
)

Constructor.

Starts connecting immediately.

All Client instances must be on the heap since they delete themselves after raising the done signal.

Use sendMessagesFrom() once, or use sendMessage() repeatedly. Wait for a messageDoneSignal() between each sendMessage().

Definition at line 34 of file gsmtpclient.cpp.

Member Function Documentation

G::Slot::Signal1< std::string > & GSmtp::Client::messageDoneSignal ( )

Returns a signal that indicates that sendMessage() has completed or failed.

Definition at line 56 of file gsmtpclient.cpp.

void GSmtp::Client::sendMessage ( unique_ptr< StoredMessage >  message)

Starts sending the given message.

Cannot be called if there is a message already in the pipeline.

The messageDoneSignal() is used to indicate that the message filtering has finished or failed.

The message is fail()ed if it cannot be sent. If this Client object is deleted before the message is sent the message is neither fail()ed or destroy()ed.

Definition at line 67 of file gsmtpclient.cpp.

void GSmtp::Client::sendMessagesFrom ( MessageStore &  store)

Sends all messages from the given message store once connected.

This must be used immediately after construction with a non-empty message store.

Once all messages have been sent the client will delete itself (see GNet::HeapClient).

The base class GNet::Client::doneSignal() can be used as an indication that all messages have been sent and the object is about to delete itself. The messageDoneSignal() is not used.

Definition at line 61 of file gsmtpclient.cpp.


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