mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-23 08:31:43 +02:00
Merge branch 'develop' of https://github.com/pocoproject/poco into develop
This commit is contained in:
@@ -148,6 +148,11 @@ public:
|
|||||||
/// Throws a SMTPException in case of a SMTP-specific error, or a
|
/// Throws a SMTPException in case of a SMTP-specific error, or a
|
||||||
/// NetException in case of a general network communication failure.
|
/// NetException in case of a general network communication failure.
|
||||||
|
|
||||||
|
void sendMessage(std::istream& istr);
|
||||||
|
/// Sends the mail message from the supplied stream. Content of the stream
|
||||||
|
/// is copied without any checking. Only the completion status is checked and,
|
||||||
|
/// if not valid, SMTPExcpetion is thrown.
|
||||||
|
|
||||||
int sendCommand(const std::string& command, std::string& response);
|
int sendCommand(const std::string& command, std::string& response);
|
||||||
/// Sends the given command verbatim to the server
|
/// Sends the given command verbatim to the server
|
||||||
/// and waits for a response.
|
/// and waits for a response.
|
||||||
@@ -162,6 +167,19 @@ public:
|
|||||||
/// Throws a SMTPException in case of a SMTP-specific error, or a
|
/// Throws a SMTPException in case of a SMTP-specific error, or a
|
||||||
/// NetException in case of a general network communication failure.
|
/// NetException in case of a general network communication failure.
|
||||||
|
|
||||||
|
void sendAddresses(const std::string& from, const Recipients& recipients);
|
||||||
|
/// Sends the message preamble by sending a MAIL FROM command,
|
||||||
|
/// and a RCPT TO command for every recipient.
|
||||||
|
///
|
||||||
|
/// Throws a SMTPException in case of a SMTP-specific error, or a
|
||||||
|
/// NetException in case of a general network communication failure.
|
||||||
|
|
||||||
|
void sendData();
|
||||||
|
/// Sends the message preamble by sending a DATA command.
|
||||||
|
///
|
||||||
|
/// Throws a SMTPException in case of a SMTP-specific error, or a
|
||||||
|
/// NetException in case of a general network communication failure.
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
enum StatusClass
|
enum StatusClass
|
||||||
{
|
{
|
||||||
|
@@ -360,6 +360,47 @@ void SMTPClientSession::sendCommands(const MailMessage& message, const Recipient
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void SMTPClientSession::sendAddresses(const std::string& from, const Recipients& recipients)
|
||||||
|
{
|
||||||
|
std::string response;
|
||||||
|
int status = 0;
|
||||||
|
|
||||||
|
std::string::size_type emailPos = from.find('<');
|
||||||
|
if (emailPos == std::string::npos)
|
||||||
|
{
|
||||||
|
std::string sender("<");
|
||||||
|
sender.append(from);
|
||||||
|
sender.append(">");
|
||||||
|
status = sendCommand("MAIL FROM:", sender, response);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
status = sendCommand("MAIL FROM:", from.substr(emailPos, from.size() - emailPos), response);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isPositiveCompletion(status)) throw SMTPException("Cannot send message", response, status);
|
||||||
|
|
||||||
|
std::ostringstream recipient;
|
||||||
|
|
||||||
|
for (Recipients::const_iterator it = recipients.begin(); it != recipients.end(); ++it)
|
||||||
|
{
|
||||||
|
|
||||||
|
recipient << '<' << *it << '>';
|
||||||
|
int status = sendCommand("RCPT TO:", recipient.str(), response);
|
||||||
|
if (!isPositiveCompletion(status)) throw SMTPException(std::string("Recipient rejected: ") + recipient.str(), response, status);
|
||||||
|
recipient.str("");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void SMTPClientSession::sendData()
|
||||||
|
{
|
||||||
|
std::string response;
|
||||||
|
int status = sendCommand("DATA", response);
|
||||||
|
if (!isPositiveIntermediate(status)) throw SMTPException("Cannot send message data", response, status);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void SMTPClientSession::sendMessage(const MailMessage& message)
|
void SMTPClientSession::sendMessage(const MailMessage& message)
|
||||||
{
|
{
|
||||||
sendCommands(message);
|
sendCommands(message);
|
||||||
@@ -402,4 +443,19 @@ int SMTPClientSession::sendCommand(const std::string& command, const std::string
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void SMTPClientSession::sendMessage(std::istream& istr)
|
||||||
|
{
|
||||||
|
std::string response;
|
||||||
|
int status = 0;
|
||||||
|
|
||||||
|
SocketOutputStream socketStream(_socket);
|
||||||
|
MailOutputStream mailStream(socketStream);
|
||||||
|
StreamCopier::copyStream(istr, mailStream);
|
||||||
|
mailStream.close();
|
||||||
|
socketStream.flush();
|
||||||
|
status = _socket.receiveStatusMessage(response);
|
||||||
|
if (!isPositiveCompletion(status)) throw SMTPException("The server rejected the message", response, status);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
} } // namespace Poco::Net
|
} } // namespace Poco::Net
|
||||||
|
Reference in New Issue
Block a user