SimpleSmtp Pile   version 0.0.1
SimpleSmtp pile.
smtp.h
Go to the documentation of this file.
1 /* ========================================================================= */
2 /* ------------------------------------------------------------------------- */
14 /*
15 Copyright (c) 2013 Raivis Strogonovs
16 
17 http://morf.lv
18 
19 Permission is hereby granted, free of charge, to any person obtaining a copy of
20 this software and associated documentation files (the "Software"), to deal in
21 the Software without restriction, including without limitation the rights to
22 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
23 of the Software, and to permit persons to whom the Software is furnished to do
24 so, subject to the following conditions:
25 
26 The above copyright notice and this permission notice shall be included in all
27 copies or substantial portions of the Software.
28 
29 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
32 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
33 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
34 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
35 SOFTWARE.
36 */
37 
38 /* ------------------------------------------------------------------------- */
39 /* ========================================================================= */
40 #ifndef __CUTTILES_SUPPORT_SMTP_INC__
41 #define __CUTTILES_SUPPORT_SMTP_INC__
42 //
43 //
44 //
45 //
46 /* INCLUDES ------------------------------------------------------------ */
47 
48 #include <simplesmtp/simplesmtp-config.h>
49 #include <usermsg/usermsg.h>
50 
51 #include <QtNetwork/QAbstractSocket>
52 #include <QtNetwork/QSslSocket>
53 #include <QString>
54 #include <QTextStream>
55 #include <QDebug>
56 #include <QtWidgets/QMessageBox>
57 #include <QByteArray>
58 #include <QFile>
59 #include <QFileInfo>
60 
61 /* INCLUDES ============================================================ */
62 //
63 //
64 //
65 //
66 /* DEFINITIONS --------------------------------------------------------- */
67 
68 /* DEFINITIONS ========================================================= */
69 //
70 //
71 //
72 //
73 /* CLASS --------------------------------------------------------------- */
74 
76 class SIMPLESMTP_EXPORT Smtp : public QObject
77 {
78  Q_OBJECT
79 
80  //
81  //
82  //
83  //
84  /* DEFINITIONS ----------------------------------------------------- */
85 
86 public:
87 
89  enum states{
90  Tls,
91  HandShake,
92  Auth,
93  User,
94  Pass,
95  Rcpt,
96  Mail,
97  Data,
98  Init,
99  Body,
100  Quit,
101  Close
102  };
103 
104  /* DEFINITIONS ===================================================== */
105  //
106  //
107  //
108  //
109  /* DATA ------------------------------------------------------------ */
110 
111 private:
112 
113  int timeout;
114  QString message;
115  QSslSocket *socket;
116  QTextStream *t;
117  QString rcpt;
118  QString response;
119  QString user;
120  QString pass;
121  QString host;
122  int port;
123  int state;
124  bool ignore_ssl_errors_;
125 
126  /* DATA ============================================================ */
127  //
128  //
129  //
130  //
131  /* FUNCTIONS ------------------------------------------------------- */
132 
133 
134 public:
135 
137  Smtp(
138  const QString &user,
139  const QString &pass,
140  const QString &host,
141  int port = 465,
142  int timeout = 30000);
143 
145  Smtp (
146  const Smtp & other);
147 
149  virtual ~Smtp();
150 
152  bool
153  sendMail (
154  UserMsg & um,
155  const QString &to,
156  const QString &subject,
157  const QString &body,
158  bool body_is_html = false,
159  QStringList files = QStringList());
160 
161 signals:
162 
164  void
165  status(
166  const QString &);
167 
168 private slots:
169 
170  void
171  stateChanged(
172  QAbstractSocket::SocketState socketState);
173 
174  void
175  errorReceived(
176  QAbstractSocket::SocketError socketError);
177 
178  void
179  disconnected();
180 
181  void
182  connected();
183 
184  void
185  readyRead();
186 
187  void
188  sslErrors(
189  QList<QSslError>);
190 
191 private:
192 
193  static bool
194  attachFiles (
195  QString & message,
196  QStringList files,
197  UserMsg & um);
198 
199  void
200  doConnections();
201 
202  /* FUNCTIONS ======================================================= */
203  //
204  //
205  //
206  //
207 
208 }; /* class Smtp */
209 
210 /* CLASS =============================================================== */
211 //
212 //
213 //
214 //
215 
216 #endif // __CUTTILES_SUPPORT_SMTP_INC__
217 /* ------------------------------------------------------------------------- */
218 /* ========================================================================= */
send an email using an smtp server
Definition: smtp.h:76
states
the states that we can have
Definition: smtp.h:89