smtpthread/ThreadedSMTPConnection.h

00001 // DOCUMENT:  ThreadedSMTPConnection-Class
00002 // VERSION:   $Revision: 1.5 $
00003 // DATE:      $Date: 2007-10-26 23:09:19 $
00004 // AUTHOR:    M.Beranek
00005 // COPYRIGHT: M.Beranek
00006 
00007 #ifndef _THREADEDSMTPCONNECTION_H
00008 #define _THREADEDSMTPCONNECTION_H
00009 
00010 #include <string>
00011 #include <errno.h>
00012 #include <sys/socket.h>
00013 #include <sys/types.h>
00014 #include <netinet/in.h>
00015 #include <arpa/inet.h>
00016 #include <pthread.h>
00017 #include "Thread.h"
00018 #include "SMTPConnection.h"
00019 
00020 using namespace std;
00021 
00022 namespace SmtpThread
00023 {
00024     
00025     
00026 #define STATE_NOT_CONNECTED  0
00027 #define STATE_CONNECTED      1
00028 #define STATE_HELO           2
00029 #define STATE_MAILFROM       3
00030 #define STATE_RCPTTO         4
00031 #define STATE_DATA           5
00032 #define STATE_DATA_SENDING   6
00033     
00034     
00035 #define SA struct sockaddr
00036 #define SAI struct sockaddr_in
00037     
00038     /**
00039      * ThreadedSMTPConnection-Class.
00040      *
00041      * This class is inherited from the Thread-class.
00042      * This means, you can initialize a ThreadedSMTPConnection-object,
00043      * setup your ThreadedSMTPConnection, start threading and
00044      * push a message to the ThreadedSMTPConnection.
00045      * While the ThreadedSMTPConnection sends the message in its thread,
00046      * you can continue doing other stuff.
00047      *
00048      * ThreadedSMTPConnection speaks plain SMTP, no ESMTP.
00049      *
00050      */
00051     class ThreadedSMTPConnection : public Thread
00052     {
00053         
00054         
00055     public:
00056         /**
00057          * Default constructor.
00058          */
00059         ThreadedSMTPConnection();
00060         
00061         /**
00062          * The main thread-loop.
00063          * Checks whether or not a mail is provided to the object
00064          * and sends the mail.
00065          */
00066         void Execute( void * arg );
00067         
00068         /**
00069          * Returns the current status of the thread.
00070          * @return bool true / false = thread is ready / is not ready to accept mssages.
00071          */
00072         bool isReady();
00073         
00074         /**
00075          * Returns the current state of the SMTP-dialog.
00076          */
00077         SMTPConnection::SMTPState getSMTPState();
00078         
00079         /**
00080          * Sets the IP-address of the SMTP-server.
00081          *
00082          * NOTE: Must be an IP-address and not a domain-name!
00083          *
00084          * @param string host IP-adress of SMTP-server.
00085          */
00086         void setSMTPHost( string host );
00087         
00088         /**
00089          * Sets the port-number to connect to.
00090          * @param int port Port-number of the SMTP-server.
00091          */
00092         void setSMTPPort( int port );
00093         
00094         /**
00095          * Sets the hostname to send within the HELO-command.
00096          * @param string myname Hostname of the sending host.
00097          */
00098         void setMyHostname( string myname );
00099         
00100         /**
00101          * Send an email to the SMTP-server.
00102          * @param string from email-address of the sender.
00103          * @param string to email-address of the receiver.
00104          * @param string msg email-body, including all additional headers.
00105          */
00106         void sendMail( string& from, string& to, string& msg );
00107         
00108         
00109     private:
00110         
00111         /** SMTP-Connection. */
00112         SMTPConnection _smtpCon;
00113         
00114         /** Current state of the SMTP-dialog. */
00115         SMTPConnection::SMTPState _smtp;
00116         
00117         /** Status of this connection. */
00118         bool _isReady;
00119         
00120         /** IP-address of the SMTP-server. */
00121         string _host;
00122         
00123         /** Hostname used in HELO-command. */
00124         string _myname;
00125         
00126         /** Port-number to connect to. */
00127         int _port;
00128         
00129         /** Status, whether we have a mail to send or not. */
00130         bool _hasMail;
00131         
00132         /* Email-address of sender. */
00133         string _from;
00134         
00135         /* Email-address of recipient. */
00136         string _to;
00137         
00138         /** Mailbody, including all headers. */
00139         string _body;
00140         
00141         
00142         
00143     };
00144     
00145 }
00146 
00147 #endif  /* _THREADEDSMTPCONNECTION_H */
00148 

Generated on Thu Nov 1 09:51:22 2007 for libSmtpThread by  doxygen 1.5.1