Library: Net
Package: Mail
Header: Poco/Net/SMTPClientSession.h
This class implements an Simple Mail Transfer Procotol (SMTP, RFC 2821) client for sending e-mail messages.
Known Derived Classes: SecureSMTPClientSession
Member Functions: close, getTimeout, isPermanentNegative, isPositiveCompletion, isPositiveIntermediate, isTransientNegative, login, loginUsingCRAM, loginUsingCRAMMD5, loginUsingCRAMSHA1, loginUsingLogin, loginUsingPlain, open, sendCommand, sendMessage, setTimeout, socket
SMTP_PORT = 25
DEFAULT_TIMEOUT = 30000000
SMTP_POSITIVE_INTERMEDIATE = 3
explicit SMTPClientSession(
const StreamSocket & socket
);
Creates the SMTPClientSession using the given socket, which must be connected to a SMTP server.
SMTPClientSession(
const std::string & host,
Poco::UInt16 port = SMTP_PORT
);
Creates the SMTPClientSession using a socket connected to the given host and port.
virtual ~SMTPClientSession();
Destroys the SMTPClientSession.
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.
Poco::Timespan getTimeout() const;
Returns the timeout for socket read operations.
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.
void login();
Calls login(hostname) with the current host name.
void login(
const std::string & hostname,
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.
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.
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.
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.
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.
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.
void setTimeout(
const Poco::Timespan & timeout
);
Sets the timeout for socket read operations.
static bool isPermanentNegative(
int status
);
static bool isPositiveCompletion(
int status
);
static bool isPositiveIntermediate(
int status
);
static bool isTransientNegative(
int status
);
void login(
const std::string & hostname,
std::string & response
);
void loginUsingCRAM(
const std::string & username,
const std::string & method,
Poco::DigestEngine & hmac
);
void loginUsingCRAMMD5(
const std::string & username,
const std::string & password
);
void loginUsingCRAMSHA1(
const std::string & username,
const std::string & password
);
void loginUsingLogin(
const std::string & username,
const std::string & password
);
void loginUsingPlain(
const std::string & username,
const std::string & password
);
DialogSocket & socket();