@@ -360,6 +360,47 @@ void SMTPClientSession::sendCommands(const MailMessage& message, const Recipient
360360}
361361
362362
363+ void SMTPClientSession::sendAddresses (const std::string& from, const Recipients& recipients)
364+ {
365+ std::string response;
366+ int status = 0 ;
367+
368+ std::string::size_type emailPos = from.find (' <' );
369+ if (emailPos == std::string::npos)
370+ {
371+ std::string sender (" <" );
372+ sender.append (from);
373+ sender.append (" >" );
374+ status = sendCommand (" MAIL FROM:" , sender, response);
375+ }
376+ else
377+ {
378+ status = sendCommand (" MAIL FROM:" , from.substr (emailPos, from.size () - emailPos), response);
379+ }
380+
381+ if (!isPositiveCompletion (status)) throw SMTPException (" Cannot send message" , response, status);
382+
383+ std::ostringstream recipient;
384+
385+ for (Recipients::const_iterator it = recipients.begin (); it != recipients.end (); ++it)
386+ {
387+
388+ recipient << ' <' << *it << ' >' ;
389+ int status = sendCommand (" RCPT TO:" , recipient.str (), response);
390+ if (!isPositiveCompletion (status)) throw SMTPException (std::string (" Recipient rejected: " ) + recipient.str (), response, status);
391+ recipient.str (" " );
392+ }
393+ }
394+
395+
396+ void SMTPClientSession::sendData ()
397+ {
398+ std::string response;
399+ int status = sendCommand (" DATA" , response);
400+ if (!isPositiveIntermediate (status)) throw SMTPException (" Cannot send message data" , response, status);
401+ }
402+
403+
363404void SMTPClientSession::sendMessage (const MailMessage& message)
364405{
365406 sendCommands (message);
@@ -402,4 +443,19 @@ int SMTPClientSession::sendCommand(const std::string& command, const std::string
402443}
403444
404445
446+ void SMTPClientSession::sendMessage (std::istream& istr)
447+ {
448+ std::string response;
449+ int status = 0 ;
450+
451+ SocketOutputStream socketStream (_socket);
452+ MailOutputStream mailStream (socketStream);
453+ StreamCopier::copyStream (istr, mailStream);
454+ mailStream.close ();
455+ socketStream.flush ();
456+ status = _socket.receiveStatusMessage (response);
457+ if (!isPositiveCompletion (status)) throw SMTPException (" The server rejected the message" , response, status);
458+ }
459+
460+
405461} } // namespace Poco::Net
0 commit comments