sptk2 logo
SPTK Home Page
Public Member Functions | Protected Member Functions | Static Protected Member Functions | List of all members
sptk::SmtpConnect Class Reference

SMTP socket. More...

#include <SmtpConnect.h>

Inheritance diagram for sptk::SmtpConnect:
sptk::BaseMailConnect sptk::TCPSocket sptk::BaseSocket

Public Member Functions

 SmtpConnect (Logger *log=nullptr)
 Default constructor. More...
 
int command (const String &cmd, bool encodeCommand=false, bool decodeResponse=false)
 
Stringsresponse ()
 The response from the server - makes sence after calling any command.
 
void cmd_auth (const String &user, const String &password)
 Logs in to the server host() More...
 
void cmd_send ()
 Sends the message. More...
 
void cmd_quit ()
 
void sendMessage () override
 Sends the message. More...
 
- Public Member Functions inherited from sptk::BaseMailConnect
 BaseMailConnect ()=default
 
virtual ~BaseMailConnect ()=default
 
String from () const noexcept
 
void from (const String &addr)
 
String to () const noexcept
 
void to (const String &addr)
 
String cc () const noexcept
 
void cc (const String &addr)
 
String bcc () const noexcept
 
void bcc (const String &addr)
 
String subject () const noexcept
 
void subject (const String &subj)
 
String body () const noexcept
 
void body (const String &body, bool smtp)
 Sets the current plain text part of e-mail message. More...
 
String attachments () const noexcept
 
void attachments (const String &attachments)
 
const BuffermessageBuffer () const noexcept
 
void mimeMessage (Buffer &buffer)
 
virtual void sendMessage ()=0
 
- Public Member Functions inherited from sptk::TCPSocket
 TCPSocket (SOCKET_ADDRESS_FAMILY domain=AF_INET, int32_t type=SOCK_STREAM, int32_t protocol=0)
 
 ~TCPSocket () override
 
void setProxy (std::shared_ptr< Proxy > proxy)
 
void close () noexcept override
 
virtual bool accept (SOCKET &clientSocketFD, struct sockaddr_in &clientInfo, std::chrono::milliseconds timeout)
 
size_t socketBytes () override
 
bool readyToRead (std::chrono::milliseconds timeout) override
 
size_t readLine (char *buffer, size_t size, char delimiter='\n')
 
size_t readLine (Buffer &buffer, char delimiter='\n')
 
size_t readLine (String &s, char delimiter='\n')
 
size_t read (uint8_t *buffer, size_t size, sockaddr_in *from=nullptr) override
 
size_t read (Buffer &buffer, size_t size, sockaddr_in *from=nullptr) override
 
size_t read (String &buffer, size_t size, sockaddr_in *from=nullptr) override
 
template<typename T >
size_t read (T &value, sockaddr_in *from=nullptr)
 
- Public Member Functions inherited from sptk::BaseSocket
SOCKET fd () const
 
void open_addr (OpenMode openMode=OpenMode::CREATE, const sockaddr_in *addr=nullptr, std::chrono::milliseconds timeout=std::chrono::milliseconds(0))
 
 BaseSocket (SOCKET_ADDRESS_FAMILY domain=AF_INET, int32_t type=SOCK_STREAM, int32_t protocol=0)
 
 BaseSocket (const BaseSocket &other)=delete
 
 BaseSocket (BaseSocket &&other) noexcept=default
 
virtual ~BaseSocket ()
 Destructor.
 
BaseSocketoperator= (const BaseSocket &other)=delete
 
BaseSocketoperator= (BaseSocket &&other) noexcept=default
 
void blockingMode (bool blocking)
 
virtual size_t socketBytes ()
 
virtual void attach (SOCKET socketHandle, bool accept)
 
virtual SOCKET detach ()
 
void host (const Host &host)
 
const Hosthost () const
 
void open (const Host &host=Host(), OpenMode openMode=OpenMode::CONNECT, bool blockingMode=true, std::chrono::milliseconds timeoutMS=std::chrono::milliseconds(0))
 
void open (const struct sockaddr_in &address, OpenMode openMode=OpenMode::CONNECT, bool blockingMode=true, std::chrono::milliseconds timeoutMS=std::chrono::milliseconds(0))
 
void bind (const char *address, uint32_t portNumber)
 
void listen (uint16_t portNumber=0)
 
virtual void close () noexcept
 
bool active () const
 
int32_t control (int flag, const uint32_t *check) const
 
void setOption (int level, int option, int value) const
 
void getOption (int level, int option, int &value) const
 
virtual size_t recv (uint8_t *buffer, size_t len)
 
virtual size_t send (const uint8_t *buffer, size_t len)
 
virtual size_t read (uint8_t *buffer, size_t size, sockaddr_in *from)
 
virtual size_t read (uint8_t *buffer, size_t size)
 
virtual size_t read (Buffer &buffer, size_t size, sockaddr_in *from)
 
size_t read (Buffer &buffer, size_t size)
 
virtual size_t read (String &buffer, size_t size, sockaddr_in *from)
 
size_t read (String &buffer, size_t size)
 
virtual size_t write (const uint8_t *buffer, size_t size, const sockaddr_in *peer)
 
size_t write (const uint8_t *buffer, size_t size)
 
virtual size_t write (const Buffer &buffer, const sockaddr_in *peer)
 
size_t write (const Buffer &buffer)
 
virtual size_t write (const String &buffer, const sockaddr_in *peer)
 
size_t write (const String &buffer)
 
virtual bool readyToRead (std::chrono::milliseconds timeout)
 
virtual bool readyToWrite (std::chrono::milliseconds timeout)
 
bool blockingMode () const
 Return current blocking mode state. More...
 

Protected Member Functions

void sendCommand (String cmd, bool encode=false)
 Sends command using SMTP protocol. More...
 
int getResponse (bool decode=false)
 Retrieves the server response after the command into internal Strings buffer. More...
 
- Protected Member Functions inherited from sptk::TCPSocket
TCPSocketReaderreader ()
 
void _open (const Host &host, OpenMode openMode, bool blockingMode, std::chrono::milliseconds timeout) override
 
void _open (const struct sockaddr_in &address, OpenMode openMode, bool blockingMode, std::chrono::milliseconds timeout) override
 
Proxyproxy ()
 
- Protected Member Functions inherited from sptk::BaseSocket
void setSocketFD (SOCKET socket)
 
int32_t domain () const
 
int32_t type () const
 
int32_t protocol () const
 
virtual void _open (const Host &host, OpenMode openMode, bool blockingMode, std::chrono::milliseconds timeoutMS)
 
virtual void _open (const struct sockaddr_in &address, OpenMode openMode, bool blockingMode, std::chrono::milliseconds timeoutMS)
 

Static Protected Member Functions

static String mime (const Buffer &buffer)
 Mime-encodes the buffer. More...
 
static String mime (const String &s)
 Mime-encodes the string. More...
 
static String unmime (const String &s)
 Mime-decodes the string. More...
 
- Static Protected Member Functions inherited from sptk::BaseMailConnect
static void mimeFile (const String &fileName, const String &fileAlias, std::stringstream &message)
 

Additional Inherited Members

- Public Types inherited from sptk::BaseSocket
enum class  OpenMode : uint8_t { CREATE , CONNECT , BIND }
 

Detailed Description

SMTP socket.

Sends an e-mail message using SMTP protocol. It uses CSocket class to establish the connection, and CBaseMailConnect to make the complete RFC 822 message.

Constructor & Destructor Documentation

◆ SmtpConnect()

sptk::SmtpConnect::SmtpConnect ( Logger log = nullptr)
explicit

Default constructor.

Parameters
logOptional log object

Member Function Documentation

◆ cmd_auth()

void sptk::SmtpConnect::cmd_auth ( const String user,
const String password 
)

Logs in to the server host()

Parameters
userUser name
passwordUser password

◆ cmd_quit()

void sptk::SmtpConnect::cmd_quit ( )

Ends the SMTP session

◆ cmd_send()

void sptk::SmtpConnect::cmd_send ( )

Sends the message.

Message is based on the information defined by the methods from CBaseMailConnect, and retrieves the server output. An alias for sendMessage().

◆ command()

int sptk::SmtpConnect::command ( const String cmd,
bool  encodeCommand = false,
bool  decodeResponse = false 
)

Sends command using SMTP protocol and retrieve the server response. The response can be read then with response() method. The CRLF characters after the command are added automatically.

Parameters
cmdSMTP protocol command
encodeCommandEncode the comand argument to Base64 or not
decodeResponseDecode the response from Base64 or not

◆ getResponse()

int sptk::SmtpConnect::getResponse ( bool  decode = false)
protected

Retrieves the server response after the command into internal Strings buffer.

The response can be read then with response() method.

Parameters
decodeDecode the response from Base64 or not

◆ mime() [1/2]

static String sptk::SmtpConnect::mime ( const Buffer buffer)
staticprotected

Mime-encodes the buffer.

Parameters
bufferSource data
Returns
MIME-encoded data

◆ mime() [2/2]

static String sptk::SmtpConnect::mime ( const String s)
staticprotected

Mime-encodes the string.

Parameters
sSource data
Returns
MIME-encoded data

◆ sendCommand()

void sptk::SmtpConnect::sendCommand ( String  cmd,
bool  encode = false 
)
protected

Sends command using SMTP protocol.

The CRLF characters after the command are added automatically.

Parameters
cmdSMTP protocol command
encodeEncode the arguments to Base64 or not

◆ sendMessage()

void sptk::SmtpConnect::sendMessage ( )
overridevirtual

Sends the message.

The message based on the information defined by the methods from CBaseMailConnect, and retrieves the server output.

Implements sptk::BaseMailConnect.

◆ unmime()

static String sptk::SmtpConnect::unmime ( const String s)
staticprotected

Mime-decodes the string.

Parameters
sSource data
Returns
Decoded data

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

Fri Oct 14 2022 09:58:44: SPTK 5.4.1