smtp_client.h

Go to the documentation of this file.
00001 #ifndef SMTP_CLIENT_CLASS
00002 #define SMTP_CLIENT_CLASS
00003 
00004 /*****************************************************************************\
00005 *                                                                             *
00006 *  Name   : smtp_client                                                       *
00007 *  Author : Chris Koeritz                                                     *
00008 *                                                                             *
00009 *******************************************************************************
00010 * Copyright (c) 2006-$now By Author.  This program is free software; you can  *
00011 * redistribute it and/or modify it under the terms of the GNU General Public  *
00012 * License as published by the Free Software Foundation; either version 2 of   *
00013 * the License or (at your option) any later version.  This is online at:      *
00014 *     http://www.fsf.org/copyleft/gpl.html                                    *
00015 * Please send any updates to: fred@gruntose.com                               *
00016 \*****************************************************************************/
00017 
00019 
00025 #include "dll_smtp_client.h"
00026 
00027 #include <basis/object_base.h>
00028 #include <sockets/definitions_sockets.h>
00029 
00030 // forward.
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     // creates an email sender that logs to the program wide logger.
00041 
00042   smtp_client(log_base &logging);
00043     // creates an email sender that sends output and errors to "logging".
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   // standard email destination management.  these are the To: header.
00113   void add_recipient(const istring &recipient);
00114   bool remove_recipient(const istring &recipient);
00115   void clear_recipients();
00116 
00117   // carbon copy destinations.  these are the CC: header.
00118   void add_carbon(const istring &cc_dest);
00119   bool remove_carbon(const istring &cc_dest);
00120   void clear_carbons();
00121 
00122 //  void add_attachment(const istring &filename);
00123 //  bool remove_attachment(const istring &filename);
00124 //  void clear_attachments();
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 

Generated on Fri Nov 21 04:29:15 2008 for HOOPLE Libraries by  doxygen 1.5.1