QGpGuiTools/SendMail.h
Go to the documentation of this file.
00001 /***************************************************************************
00002 **
00003 **  This file is part of QGpGuiTools.
00004 **
00005 **  This library is free software; you can redistribute it and/or
00006 **  modify it under the terms of the GNU Lesser General Public
00007 **  License as published by the Free Software Foundation; either
00008 **  version 2.1 of the License, or (at your option) any later version.
00009 **
00010 **  This file is distributed in the hope that it will be useful, but WITHOUT
00011 **  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 **  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
00013 **  License for more details.
00014 **
00015 **  You should have received a copy of the GNU Lesser General Public
00016 **  License along with this library; if not, write to the Free Software
00017 **  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00018 **
00019 **  See http://www.geopsy.org for more information.
00020 **
00021 **  Created : 2004-12-09
00022 **  Authors :
00023 **    Marc Wathelet
00024 **    Marc Wathelet (ULg, Liège, Belgium)
00025 **    Marc Wathelet (LGIT, Grenoble, France)
00026 **
00027 ***************************************************************************/
00028 
00029 #ifndef SENDMAIL_H
00030 #define SENDMAIL_H
00031 
00032 #include <QtCore>
00033 
00034 #include "QGpGuiToolsDLLExport.h"
00035 
00036 class QTcpSocket;
00037 
00038 namespace QGpGuiTools {
00039 
00040 class QGPGUITOOLS_EXPORT SendMail : public QObject
00041 {
00042   Q_OBJECT
00043 public:
00044   SendMail(const QString &smtp, const QString &from, const QString &to,
00045               const QString &subject, const QString &body,
00046               const QStringList * files=0);
00047   ~SendMail();
00048 public slots:
00049   void send();
00050 private slots:
00051   void readyRead();
00052   void connected();
00053   void dataWritten(qint64 nbytes);
00054 signals:
00055   void dataProgressValue(int val);
00056   void dataProgressMaximum(int val);
00057   void status(const QString &);
00058   void finished(bool);
00059 private:
00060   QString encode(uchar * buf, int bufLen);
00061   void addAttachments(); 
00062   void cleanTmpDir(QDir& tmp);
00063   enum State {
00064     Init,
00065     Mail,
00066     Rcpt,
00067     Data,
00068     Body,
00069     Quit,
00070     Close
00071   };
00072 
00073   QString _smtp;
00074   QString _message;
00075   QString _from;
00076   QString _to;
00077   QStringList _files;
00078 
00079   QTcpSocket * _socket;
00080   QTextStream * _t;
00081   int _state;
00082   int _dataWritten;
00083 };
00084 
00085 } // namespace QGpGuiTools
00086 
00087 #endif // SENDMAIL_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines