E-MailRelay
|
A class which acts as an SMTP client, sending messages to a remote SMTP server. More...
#include <gsmtpclient.h>
Classes | |
struct | Config |
A structure containing GSmtp::Client configuration parameters. More... | |
struct | MessageDoneInfo |
Signal parameters for GNet::Client::messageDoneSignal() More... | |
Public Member Functions | |
Client (GNet::EventState, FilterFactoryBase &, const GNet::Location &remote, const GAuth::SaslClientSecrets &, const Config &config) | |
Constructor. More... | |
~Client () override | |
Destructor. More... | |
void | sendMessage (std::unique_ptr< GStore::StoredMessage > message) |
Starts sending the given message. More... | |
void | quitAndFinish () |
Finishes a sendMessage() sequence. More... | |
G::Slot::Signal< const MessageDoneInfo & > & | messageDoneSignal () noexcept |
Returns a signal that indicates that sendMessage() has completed or failed. More... | |
Client (const Client &)=delete | |
Client (Client &&)=delete | |
Client & | operator= (const Client &)=delete |
Client & | operator= (Client &&)=delete |
![]() | |
Client (EventState, const Location &remote_location, const Config &) | |
Constructor. More... | |
~Client () override | |
Destructor. More... | |
void | connect () |
Initiates a connection to the remote server. More... | |
bool | connected () const |
Returns true if connected to the peer. More... | |
bool | hasConnected () const |
Returns true if ever connected(). More... | |
std::string | peerAddressString (bool with_port=true) const |
Returns the peer address display string or the empty string if not connected(). More... | |
void | disconnect () |
Aborts the connection and destroys the object's internal state, resulting in a zombie object. More... | |
Address | localAddress () const override |
Returns the local address. More... | |
Address | peerAddress () const override |
Returns the peer address. More... | |
std::string | connectionState () const override |
Returns the connection state display string. More... | |
std::string | peerCertificate () const override |
Returns the peer's TLS certificate. More... | |
Location | remoteLocation () const |
Returns a Location structure, including the result of name lookup if available. More... | |
bool | send (const std::string &data) |
Sends data to the peer and starts the response timer (if configured). More... | |
bool | send (std::string_view data) |
Overload for string_view. More... | |
bool | send (const std::vector< std::string_view > &data, std::size_t offset=0) |
Overload for scatter/gather segments. More... | |
G::Slot::Signal< const std::string &, const std::string &, const std::string & > & | eventSignal () noexcept |
Returns a signal that indicates that something interesting has happened. More... | |
void | doOnDelete (const std::string &reason, bool done) |
This should be called by the Client owner (typically ClientPtr) just before this Client object is deleted as the result of an exception. More... | |
bool | finished () const |
Returns true if finish() has been called. More... | |
LineBufferState | lineBuffer () const |
Returns information about the state of the internal line-buffer. More... | |
bool | secureConnectCapable () const |
Returns true if currently connected and secureConnect() can be used. More... | |
Client (const Client &)=delete | |
Client (Client &&)=delete | |
Client & | operator= (const Client &)=delete |
Client & | operator= (Client &&)=delete |
bool | send (const char *, std::size_t)=delete |
bool | send (const char *)=delete |
bool | send (const std::string &, std::size_t)=delete |
![]() | |
virtual | ~Connection ()=default |
Destructor. | |
virtual Address | localAddress () const =0 |
Returns the connection's local address. More... | |
virtual Address | peerAddress () const =0 |
Returns the connection's peer address. More... | |
virtual std::string | connectionState () const =0 |
Returns the connection state as a display string. More... | |
virtual std::string | peerCertificate () const =0 |
Returns the peer's TLS certificate. More... | |
![]() | |
virtual | ~ExceptionSource () |
Destructor. | |
ExceptionSource (const ExceptionSource &)=delete | |
ExceptionSource (ExceptionSource &&)=delete | |
ExceptionSource & | operator= (const ExceptionSource &)=delete |
ExceptionSource & | operator= (ExceptionSource &&)=delete |
Static Public Member Functions | |
static std::string | eventLoggingString (const GStore::StoredMessage *, const Config &) |
Returns an event logging string for the given message. More... | |
Additional Inherited Members | |
![]() | |
StreamSocket & | socket () |
Returns a reference to the socket. Throws if not connected. More... | |
const StreamSocket & | socket () const |
Returns a const reference to the socket. Throws if not connected. More... | |
void | finish () |
Indicates that the last data has been sent and the client is expecting a peer disconnect. More... | |
void | clearInput () |
Clears the input LineBuffer and cancels the response timer if running. More... | |
virtual bool | onReceive (const char *data, std::size_t size, std::size_t eolsize, std::size_t linesize, char c0)=0 |
Called with received data. More... | |
virtual void | onConnect ()=0 |
Called once connected. | |
virtual void | onSendComplete ()=0 |
Called when all residual data from send() has been sent. | |
virtual void | onDelete (const std::string &reason)=0 |
Called from doOnDelete(), typically just before a ClientPtr destroys the Client as the result of handling an exception. More... | |
void | secureConnect () |
Starts TLS/SSL client-side negotiation. More... | |
A class which acts as an SMTP client, sending messages to a remote SMTP server.
A GSmtp::Client is-a GNet::Client so when it is destroyed as the result of an exception the owner should call GNet::Client::doOnDelete() (like GNet::ClientPtr does). The onDelete() implementation in this class fails the current message if the GNet::Client was not finish()ed (see quitAndFinish()) and the exception was not GNet::Done.
Definition at line 63 of file gsmtpclient.h.
GSmtp::Client::Client | ( | GNet::EventState | es, |
FilterFactoryBase & | ff, | ||
const GNet::Location & | remote, | ||
const GAuth::SaslClientSecrets & | secrets, | ||
const Config & | config | ||
) |
Constructor.
Expects sendMessage() immediately after construction.
A messageDoneSignal() is emitted when the message has been sent, allowing the next sendMessage(). Use quitAndFinish() at the end.
Definition at line 34 of file gsmtpclient.cpp.
|
override |
Destructor.
Definition at line 50 of file gsmtpclient.cpp.
|
static |
Returns an event logging string for the given message.
Definition at line 285 of file gsmtpclient.cpp.
|
noexcept |
Returns a signal that indicates that sendMessage() has completed or failed.
Definition at line 62 of file gsmtpclient.cpp.
void GSmtp::Client::quitAndFinish | ( | ) |
Finishes a sendMessage() sequence.
Sends a QUIT command and finish()es the GNet::Client.
Definition at line 233 of file gsmtpclient.cpp.
void GSmtp::Client::sendMessage | ( | std::unique_ptr< GStore::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.
Does nothing if there are no message recipients.
Definition at line 67 of file gsmtpclient.cpp.