#include "mail.hpp" #include mailer::mailer( std::string server, unsigned short port, std::string username, std::string password, std::string from ) : server( server ), port( port ), username( username ), password( password ), from( from ) { quickmail_initialize( ); mailobj = quickmail_create( NULL, NULL ); } mailer::~mailer( ) { quickmail_destroy( mailobj ); quickmail_cleanup( ); } void mailer::send( ) { if( !from.empty( ) ) { quickmail_set_from( mailobj, from.c_str( ) ); } if( !to.empty( ) ) { quickmail_add_to( mailobj, to.c_str( ) ); } if( !subject.empty( ) ) { quickmail_set_subject( mailobj, subject.c_str( ) ); } if( !body.empty( ) ) { quickmail_add_body_memory( mailobj, "text/plain", const_cast( body.c_str( ) ), body.size( ), 0 ); } _hasError = false; const char *errmsg; errmsg = quickmail_send( mailobj, server.c_str( ), port, username.c_str( ), password.c_str( ) ); if( errmsg != NULL ) { _hasError = true; lastErrorMsg = std::string( errmsg ); } } bool mailer::hasError( ) { return _hasError; } std::string mailer::getLastError( ) { return lastErrorMsg; }