Poco::Net

class SMTPClientSession

Library: Net
Package: Mail
Header: Poco/Net/SMTPClientSession.h

Description

This class implements an Simple Mail Transfer Procotol (SMTP, RFC 2821) client for sending e-mail messages.

Member Summary

Member Functions: close, getTimeout, isPermanentNegative, isPositiveCompletion, isPositiveIntermediate, isTransientNegative, login, loginUsingCRAM_MD5, loginUsingLogin, loginUsingPlain, open, sendCommand, sendMessage, setTimeout

Enumerations

Anonymous

SMTP_PORT = 25

Anonymous protected

DEFAULT_TIMEOUT = 30000000

LoginMethod

AUTH_NONE

AUTH_CRAM_MD5

AUTH_LOGIN

StatusClass protected

SMTP_POSITIVE_COMPLETION = 2

SMTP_POSITIVE_INTERMEDIATE = 3

SMTP_TRANSIENT_NEGATIVE = 4

SMTP_PERMANENT_NEGATIVE = 5

Constructors

SMTPClientSession

SMTPClientSession(
    const StreamSocket & socket
);

Creates the SMTPClientSession using the given socket, which must be connected to a SMTP server.

SMTPClientSession

SMTPClientSession(
    const std::string & host,
    Poco::UInt16 port = SMTP_PORT
);

Creates the SMTPClientSession using a socket connected to the given host and port.

Destructor

~SMTPClientSession virtual

virtual ~SMTPClientSession();

Destroys the SMTPClientSession.

Member Functions

close

void close();

Sends a QUIT command and closes the connection to the server.

Throws a SMTPException in case of a SMTP-specific error, or a NetException in case of a general network communication failure.

getTimeout

Poco::Timespan getTimeout() const;

Returns the timeout for socket read operations.

login

void login(
    const std::string & hostname
);

Greets the SMTP server by sending a EHLO command with the given hostname as argument.

If the server does not understand the EHLO command, a HELO command is sent instead.

Throws a SMTPException in case of a SMTP-specific error, or a NetException in case of a general network communication failure.

login

void login();

Calls login(hostname) with the current host name.

login

void login(
    LoginMethod loginMethod,
    const std::string & username,
    const std::string & password
);

Logs in to the SMTP server using the given authentication method and the given credentials.

open

void open();

Reads the initial response from the SMTP server.

Usually called implicitly through login(), but can also be called explicitly to implement different forms of SMTP authentication.

Does nothing if called more than once.

sendCommand

int sendCommand(
    const std::string & command,
    std::string & response
);

Sends the given command verbatim to the server and waits for a response.

Throws a SMTPException in case of a SMTP-specific error, or a NetException in case of a general network communication failure.

sendCommand

int sendCommand(
    const std::string & command,
    const std::string & arg,
    std::string & response
);

Sends the given command verbatim to the server and waits for a response.

Throws a SMTPException in case of a SMTP-specific error, or a NetException in case of a general network communication failure.

sendMessage

void sendMessage(
    const MailMessage & message
);

Sends the given mail message by sending a MAIL FROM command, a RCPT TO command for every recipient, and a DATA command with the message headers and content.

Throws a SMTPException in case of a SMTP-specific error, or a NetException in case of a general network communication failure.

setTimeout

void setTimeout(
    const Poco::Timespan & timeout
);

Sets the timeout for socket read operations.

isPermanentNegative protected static inline

static bool isPermanentNegative(
    int status
);

isPositiveCompletion protected static inline

static bool isPositiveCompletion(
    int status
);

isPositiveIntermediate protected static inline

static bool isPositiveIntermediate(
    int status
);

isTransientNegative protected static inline

static bool isTransientNegative(
    int status
);

login protected

void login(
    const std::string & hostname,
    std::string & response
);

loginUsingCRAM_MD5 protected

void loginUsingCRAM_MD5(
    const std::string & username,
    const std::string & password
);

loginUsingLogin protected

void loginUsingLogin(
    const std::string & username,
    const std::string & password
);

loginUsingPlain protected

void loginUsingPlain(
    const std::string & username,
    const std::string & password
);