KSmtp::Session Class

The Session class. More...

Header: #include <KSMTP/Session>
CMake: find_package(KPim6 REQUIRED COMPONENTS SMTP)
target_link_libraries(mytarget PRIVATE KPim6::SMTP)

Public Types

enum EncryptionMode { Unencrypted, TLS, STARTTLS }

Public Functions

Session(const QString &hostName, quint16 port, QObject *parent = nullptr)
bool allowsDsn() const
bool allowsTls() const
QStringList availableAuthModes() const
KSmtp::Session::EncryptionMode encryptionMode() const
QString hostName() const
void open()
quint16 port() const
void quit()
void setCustomHostname(const QString &hostname)
void setEncryptionMode(KSmtp::Session::EncryptionMode mode)
void setSocketTimeout(int ms)
void setUseNetworkProxy(bool useProxy)
int sizeLimit() const
int socketTimeout() const

Signals

void connectionError(const QString &error)
void stateChanged(KSmtp::Session::State state)

Detailed Description

Member Type Documentation

enum Session::EncryptionMode

Various possible values for the "EncryptionMode". Transport encryption for a session.

ConstantValueDescription
KSmtp::Session::Unencrypted0Use no encryption.
KSmtp::Session::TLS1Use TLS encryption on the socket.
KSmtp::Session::STARTTLS2Use STARTTLS to upgrade an unencrypted connection to encrypted after the initial handshake.

Member Function Documentation

[explicit] Session::Session(const QString &hostName, quint16 port, QObject *parent = nullptr)

Creates a new SMTP session to the specified host and port. After creating the session, call setUseNetworkProxy() if necessary and then either open() to open the connection. @sa open()

bool Session::allowsDsn() const

Returns true if the SMTP server has indicated that it allows Delivery Status Notification (DSN) support, false otherwise.

bool Session::allowsTls() const

Returns true if the SMTP server has indicated that it allows TLS connections, false otherwise. The session must be at least in the NotAuthenticated state. Before that, allowsTls() always returns false.

@sa KSmtp::LoginJob::setUseTls()

QStringList Session::availableAuthModes() const

@todo: return parsed auth modes, instead of strings.

[signal] void Session::connectionError(const QString &error)

KSmtp::Session::EncryptionMode Session::encryptionMode() const

Returns the requested encryption mode for this session.

See also setEncryptionMode().

QString Session::hostName() const

Returns the host name that has been provided in the Session's constructor @sa port()

void Session::open()

Opens the connection to the server.

You should connect to stateChanged() before calling this method, and wait until the session's state is NotAuthenticated (Session is ready for a LoginJob) or Disconnected (connecting to the server failed)

Make sure to call \sa setEncryptionMode() before.

See also setEncryptionMode.

quint16 Session::port() const

Returns the port number that has been provided in the Session's constructor @sa hostName()

void Session::quit()

Requests the server to quit the connection.

This sends a "QUIT" command to the server and will not close the connection until it receives a response. That means you should not delete this object right after calling close, instead wait for stateChanged() to change to Disconnected.

See RFC 821, Chapter 4.1.1, "QUIT".

void Session::setCustomHostname(const QString &hostname)

Custom hostname to send in EHLO/HELO command

void Session::setEncryptionMode(KSmtp::Session::EncryptionMode mode)

Sets the encryption mode for this session. Has to be called before open().

See also encryptionMode().

void Session::setSocketTimeout(int ms)

setSocketTimeout ms

See also socketTimeout().

void Session::setUseNetworkProxy(bool useProxy)

Sets whether the SMTP network connection should use the system proxy settings

The default is to not use the proxy.

int Session::sizeLimit() const

Returns the maximum message size in bytes that the server accepts. You can use SendJob::size() to get the size of the message that you are trying to send @sa KSmtp::SendJob::size()

int Session::socketTimeout() const

socketTimeout Returns

See also setSocketTimeout().

[signal] void Session::stateChanged(KSmtp::Session::State state)