@@ -365,6 +365,47 @@ void SMTPClientSession::sendCommands(const MailMessage& message, const Recipient
365365}
366366
367367
368+ void SMTPClientSession::sendAddresses (const std::string& from, const Recipients& recipients)
369+ {
370+ std::string response;
371+ int status = 0 ;
372+
373+ std::string::size_type emailPos = from.find (' <' );
374+ if (emailPos == std::string::npos)
375+ {
376+ std::string sender (" <" );
377+ sender.append (from);
378+ sender.append (" >" );
379+ status = sendCommand (" MAIL FROM:" , sender, response);
380+ }
381+ else
382+ {
383+ status = sendCommand (" MAIL FROM:" , from.substr (emailPos, from.size () - emailPos), response);
384+ }
385+
386+ if (!isPositiveCompletion (status)) throw SMTPException (" Cannot send message" , response, status);
387+
388+ std::ostringstream recipient;
389+
390+ for (Recipients::const_iterator it = recipients.begin (); it != recipients.end (); ++it)
391+ {
392+
393+ recipient << ' <' << *it << ' >' ;
394+ int status = sendCommand (" RCPT TO:" , recipient.str (), response);
395+ if (!isPositiveCompletion (status)) throw SMTPException (std::string (" Recipient rejected: " ) + recipient.str (), response, status);
396+ recipient.str (" " );
397+ }
398+ }
399+
400+
401+ void SMTPClientSession::sendData ()
402+ {
403+ std::string response;
404+ int status = sendCommand (" DATA" , response);
405+ if (!isPositiveIntermediate (status)) throw SMTPException (" Cannot send message data" , response, status);
406+ }
407+
408+
368409void SMTPClientSession::sendMessage (const MailMessage& message)
369410{
370411 sendCommands (message);
@@ -408,4 +449,19 @@ int SMTPClientSession::sendCommand(const std::string& command, const std::string
408449}
409450
410451
452+ void SMTPClientSession::sendMessage (std::istream& istr)
453+ {
454+ std::string response;
455+ int status = 0 ;
456+
457+ SocketOutputStream socketStream (_socket);
458+ MailOutputStream mailStream (socketStream);
459+ StreamCopier::copyStream (istr, mailStream);
460+ mailStream.close ();
461+ socketStream.flush ();
462+ status = _socket.receiveStatusMessage (response);
463+ if (!isPositiveCompletion (status)) throw SMTPException (" The server rejected the message" , response, status);
464+ }
465+
466+
411467} } // namespace Poco::Net
0 commit comments