00001 #ifndef SMTP_CLIENT_CLASS
00002 #define SMTP_CLIENT_CLASS
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00019
00025 #include "dll_smtp_client.h"
00026
00027 #include <basis/object_base.h>
00028 #include <sockets/definitions_sockets.h>
00029
00030
00031 class istring;
00032 class log_base;
00033 class stdio_redirecter;
00034 class string_array;
00035
00036 class SMTP_CLIENT_CLASS_STYLE smtp_client
00037 {
00038 public:
00039 smtp_client();
00040
00041
00042 smtp_client(log_base &logging);
00043
00044
00045 virtual ~smtp_client();
00046
00047 #define SC_SMTP_DEFAULT_PORT 25
00049
00050 enum outcomes {
00052 OKAY = common::OKAY,
00054 BAD_INPUT = common::BAD_INPUT,
00056 TIMED_OUT = common::TIMED_OUT,
00058 ACCESS_DENIED = common::ACCESS_DENIED,
00059
00061 NO_SERVER = communication_commons::NO_SERVER,
00063 NO_CONNECTION = communication_commons::NO_CONNECTION
00064 };
00065
00066 static const char *outcome_name(const outcome &to_name);
00068
00069 IMPLEMENT_CLASS_NAME("smtp_client");
00070
00071 istring text_form() const;
00073
00074 static istring prune_address(const istring &to_prune, istring &name);
00076
00079 static bool validate_address(const istring &to_check);
00081
00085 void setup_session(const istring &server_name,
00086 int smtp_port = SC_SMTP_DEFAULT_PORT,
00087 const istring &user_name = istring::empty_string(),
00088 const istring &password = istring::empty_string());
00090
00093 void set_server(const istring &server_name);
00094 void set_port(int smtp_port);
00095 void set_auth_user(const istring &user_name);
00096 void set_auth_password(const istring &password);
00097 void set_timeout(int timeout);
00099
00100 void setup_message(const istring &sender_email, const istring &subject,
00101 const istring &message_body,
00102 const istring &one_recipient = istring::empty_string());
00104
00108 void set_sender(const istring &sender_email);
00109 void set_subject(const istring &subject);
00110 void set_body(const istring &message_body);
00111
00112
00113 void add_recipient(const istring &recipient);
00114 bool remove_recipient(const istring &recipient);
00115 void clear_recipients();
00116
00117
00118 void add_carbon(const istring &cc_dest);
00119 bool remove_carbon(const istring &cc_dest);
00120 void clear_carbons();
00121
00122
00123
00124
00125
00126 outcome send_email();
00128
00132 private:
00133 log_base *_logging;
00134 istring *_sess_server;
00135 int _sess_port;
00136 istring *_sess_user;
00137 istring *_sess_password;
00138 istring *_msg_sender;
00139 istring *_msg_subject;
00140 istring *_msg_body;
00141 string_array *_msg_attachments;
00142 string_array *_msg_recipients;
00143 string_array *_msg_carbons;
00144 int _timeout;
00145
00146 bool okay_exit_value(int value);
00148
00149 bool get_outputs(stdio_redirecter &msmtp, byte_array &received);
00151
00153 };
00154
00155 #endif
00156