00001 #ifndef MAILSENDER_H
00002 #define MAILSENDER_H
00003
00004 #include <QString>
00005 #include <QStringList>
00006 #include <QObject>
00007 #include <QTcpSocket>
00008 #include <QPointer>
00009 #include <QAuthenticator>
00010 #include <QSslSocket>
00011
00012
00013
00014 class MailSender : public QObject
00015 {
00016 Q_OBJECT
00017
00018 public:
00019
00020 enum Priority
00021 {
00022 high,
00023 normal,
00024 low
00025 };
00026 enum ContentType
00027 {
00028 text,
00029 html,
00030 multipartmixed
00031 };
00032 enum Encoding
00033 {
00034 _7bit,
00035 _8bit,
00036 base64
00037 };
00038 enum ISO
00039 {
00040 utf8,
00041 iso88591
00042 };
00043
00044 MailSender(const QString &smtpServer, const QString &from, const QStringList &to, const QString &subject, const QString &body);
00045 ~MailSender();
00046 bool send();
00047 QString lastError() {return _lastError;}
00048 QString lastCmd() {return _lastCmd;}
00049 QString lastResponse() {return _lastResponse;}
00050 QString lastMailData() {return _lastMailData;}
00051
00052 void setSmtpServer(const QString &smtpServer) { _smtpServer = smtpServer; }
00053 void setPort(int port) { _port = port; }
00054 void setTimeout(int timeout) { _timeout = timeout; }
00055 void setLogin(const QString &login, const QString &passwd) { _login = login; _password = passwd; }
00056 void setSsl(bool ssl) { _ssl = ssl; }
00057 void setCc(const QStringList &cc) { _cc = cc; }
00058 void setBcc(const QStringList &bcc) { _bcc = bcc; }
00059 void setAttachments(const QStringList &attachments) { _attachments = attachments; }
00060 void setReplyTo(const QString &replyTo) { _replyTo = replyTo; }
00061 void setPriority(Priority priority) { _priority = priority; }
00062 void setFrom(const QString &from);
00063 void setTo(const QStringList &to) { _to = to; }
00064 void setSubject(const QString &subject) { _subject = subject; }
00065 void setBody(const QString &body) { _body = body; }
00066 void setFromName(const QString &fromName) { _fromName = fromName; }
00067 void setContentType(ContentType contentType) { _contentType = contentType; }
00068 void setISO(ISO iso);
00069 void setEncoding(Encoding encoding);
00070 void setProxyAuthenticator(const QAuthenticator &authenticator);
00071
00072 private slots:
00073 void errorReceived(QAbstractSocket::SocketError socketError);
00074 void proxyAuthentication(const QNetworkProxy &proxy, QAuthenticator *authenticator);
00075
00076 private:
00077 QString getMimeType(QString ext);
00078 QString mailData();
00079 QString contentType();
00080 bool read(const QString &waitfor);
00081 bool sendCommand(const QString &cmd, const QString &waitfor);
00082 void error(const QString &msg);
00083
00084 QString _smtpServer;
00085 int _port;
00086 int _timeout;
00087 QString _login;
00088 QString _password;
00089 QPointer<QTcpSocket> _socket;
00090 bool _ssl;
00091 QAuthenticator _authenticator;
00092 QString _lastError;
00093 QString _lastCmd;
00094 QString _lastResponse;
00095 QString _lastMailData;
00096
00097 QString _from;
00098 QStringList _to;
00099 QString _subject;
00100 QString _body;
00101 QStringList _cc;
00102 QStringList _bcc;
00103 QStringList _attachments;
00104 QString _fromName;
00105 QString _replyTo;
00106 Priority _priority;
00107 ContentType _contentType;
00108 QString _encoding;
00109 QString _iso;
00110 QString _bodyCodec;
00111 QString _confirmTo;
00112 };
00113
00114 #endif