00001 /* 00002 oc_Mail.h 00003 Class wrapper for SMTP 00004 Author: David McCombs, w3 systems development 00005 Copyright 2003 00006 00007 */ 00008 #ifndef OC_MAIL_H 00009 #define OC_MAIL_H 00010 00011 #include <cstdio> 00012 #include <string> 00013 #include <map> 00014 #include "ocCommon.h" 00015 #include "ocString.h" 00016 #include "oc_SMTP.h" 00017 00018 extern "C"{ 00019 #include <time.h> 00020 } 00021 00022 typedef map< string, string> strStrMap; 00023 00024 /* 00025 Class definition 00026 */ 00027 class ocSendMail 00028 { 00029 private: 00030 string m_strExePath; 00031 string m_strHeaders; 00032 ocString m_strBody; 00033 string m_beginBoundary; 00034 string m_endBoundary; 00035 strStrMap m_addresses; 00036 string m_content_type; 00037 ocFiles m_files; 00038 tm tm_time; 00039 oc_SMTP smtp; 00040 string send_result; 00041 00042 void getTime( void ); 00043 string makeBoundary( void ); 00044 void decodeFile( ocFiles::iterator & pos ); 00045 public: 00046 00047 00048 // constructor & destructor 00049 ocSendMail( string address = "127.0.0.1", int port=25 ); 00050 ~ocSendMail(); 00051 00052 bool loadAddresses ( string path ); 00053 string getAddress( string name ); 00054 00055 // open mail route to send mail to 00056 bool openRoute( string from, 00057 string to, 00058 string subject, 00059 string cc = "", 00060 string bcc = "", 00061 string serverAddress = "127.0.0.1" ); 00062 00063 // add a custom header 00064 bool addHeader ( string header, string value ); 00065 00066 // set the mime type (text/plain by default) 00067 bool setMimeType( string type ); 00068 00069 // write a line into the message body 00070 bool write( string text ); 00071 00072 // send the whole mail message 00073 bool send( void ); 00074 00075 // add inline attachment 00076 bool attach ( ocFile & inFile ); 00077 00078 // useful, so make it available 00079 string makeUUID(void); 00080 00081 // last string of results of SMTP commands 00082 inline string & sendResult( void ) 00083 { return send_result; } 00084 00085 // return the body 00086 inline string & body( void ) 00087 { return m_strBody; } 00088 00089 }; 00090 00091 #endif 00092
1.5.5