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, open, sendCommand, sendMessage, setTimeout

Enumerations

Anonymous

SMTP_PORT = 25

Anonymous protected

DEFAULT_TIMEOUT = 30000000

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.

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
);