/* $Revision: 1 $ $Date: 19/08/04 12:48 $ Copyright © 1999-2004, FSL Technologies Limited. Contact "http://fost3.fsltech.com". */ #include "stdafx.h" #include #include #include #include using namespace FSLib; using namespace FSLib::Exceptions; namespace { Revision c_revision( L"$Archive: /FOST.3/F3Util/smtp.cpp $", __DATE__, L"$Revision: 1 $", L"$Date: 19/08/04 12:48 $" ); void check( boost::scoped_ptr< TCPStream > &cnx, int code, const FSLib::wstring &command ) { FSLib::wstring resp; char c; do { cnx->get( c ); resp += c; } while( cnx->good() && (c!='\n') ); FSLib::wstring p( toString( code ) + L" " ); if ( resp.substr( 0, p.size() ) != p ) throw FSLib::Exceptions::Protocol( L"Expected server response of " + p + L"for command " + command + L" but received {" + trim( resp ) + L"}" ); } } Smtp::Smtp( const Host & mailhost ) : m_connection( new TCPStream( mailhost, 25 ) ) { check( m_connection, 220, L"" ); } void Smtp::Hello() { *m_connection << "HELO FSIP\r\n"; check( m_connection, 250, L"HELO" ); } void Smtp::MailFrom( const wstring & who ) { *m_connection << "MAIL FROM:<" << narrow( who ) << ">\r\n"; check( m_connection, 250, L"MAIL FROM" ); } void Smtp::RcptTo( const wstring &who ) { *m_connection << "RCPT TO:<" << narrow( who ) << ">\r\n"; check( m_connection, 250, L"RCPT TO" ); } void Smtp::Data( const wstring & m ) { *m_connection << "DATA\r\n"; check( m_connection, 354, L"DATA" ); *m_connection << narrow( m ) << "\r\n.\r\n"; check( m_connection, 250, L"" ); } void Smtp::Quit() { *m_connection << "QUIT\r\n"; check( m_connection, 221, L"QUIT" ); } /* $History: smtp.cpp $ * * ***************** Version 1 ***************** * User: Kirit Date: 19/08/04 Time: 12:48 * Created in $/FOST.3/F3Util * Basic functioning SMTP emailer. */