Qore SmtpClient Module Reference  1.6
SmtpClient.qm.dox.h
1 // -*- mode: c++; indent-tabs-mode: nil -*-
2 // @file SmtpClient.qm SmtpClient module definition
3 
4 /* SmtpClient.qm Copyright 2012 - 2017 Qore Technologies, s.r.o.
5 
6  Original Authors: Wolfgang Ritzinger, Marian Bonda, Pavol Potoncok
7 
8  Permission is hereby granted, free of charge, to any person obtaining a
9  copy of this software and associated documentation files (the "Software"),
10  to deal in the Software without restriction, including without limitation
11  the rights to use, copy, modify, merge, publish, distribute, sublicense,
12  and/or sell copies of the Software, and to permit persons to whom the
13  Software is furnished to do so, subject to the following conditions:
14 
15  The above copyright notice and this permission notice shall be included in
16  all copies or substantial portions of the Software.
17 
18  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24  DEALINGS IN THE SOFTWARE.
25 */
26 
27 // minimum qore version
28 
29 // need mime definitions
30 
31 // need MailMessage classes
32 
33 
34 // assume local var scope, do not use "$" for vars, members, and method calls
35 
36 
153 
161 namespace SmtpClient {
163  const DefaultReadTimeout = 15s;
164 
167 
170 
171 public:
173 
180  constructor(string sender, string subject) ;
181 
182  };
183 
186 
187 public:
188  };
189 
191 
194  class SmtpClient {
195 
196 public:
198  private :
199  Socket sock();
200 
201  // connect string
202  string connect;
203 
204  // ensures exclusive access to the object
205  Mutex mutex();
206 
207  bool nosend = False;
208 
209  // optional info log closure
210  *code log_info;
211 
212  // optional debug log closure
213  *code log_debug;
214 
215  // tls flag (ie \c "STARTTLS" flag; ie application layer security)
216  bool tls = False;
217 
218  // ssl flag (for TLS/SSL connections - ie transport layer instead of application layer security)
219  bool ssl = False;
220 
221  // esmtp flag
222  bool esmtp;
223 
224  // authentication credentials
225  *string user;
226  *string pass;
227 
228  // logged in flag
229  bool logged_in = False;
230 
231  // read timeout in milliseconds
232  timeout readTimeout = DefaultReadTimeout;
233 
234  // connect timeout in milliseconds
235  timeout connectTimeout = DefaultConnectTimeout;
236 
237  // HELO/EHLO reply
238  hash hello_reply;
239 
240  const MaxDebugLine = 2048;
241 
242 public:
244 
245  public :
247  const SmtpPort = 25;
248 
250  const SmtpsPort = 465;
251 
253  const EsmtpPort = 587;
254 
256  const Protocols = (
257  "smtp": (
258  "port": SmtpPort,
259  "ssl": False,
260  "tls": False,
261  ),
262  "smtps": (
263  "port": SmtpsPort,
264  "ssl": True,
265  "tls": False,
266  ),
267  "smtptls": (
268  "port": SmtpsPort,
269  "ssl": False,
270  "tls": True,
271  ),
272  "esmtp": (
273  "port": EsmtpPort,
274  "ssl": False,
275  "tls": False,
276  ),
277  "esmtptls": (
278  "port": EsmtpPort,
279  "ssl": False,
280  "tls": True,
281  ),
282  );
283 
284 public:
285 
287 
292  constructor(string host, softint port, *code log, *code dbglog);
293 
294 
296 
309  constructor(string url, *code log, *code dbglog);
310 
311 
313 
315  destructor();
316 
317 
319 
321  tls(bool n_tls);
322 
323 
325  bool tls();
326 
327 
329 
331  ssl(bool n_ssl);
332 
333 
335  bool ssl();
336 
337 
339 
346  setUserPass(string n_user, string n_pass);
347 
348 
350  test(bool ns);
351 
352 
354  bool test();
355 
356 
358 
362  connect();
363 
364 
366  bool isConnected();
367 
368 
370 
372  disconnect();
373 
374 
376  setReadTimeout(timeout to);
377 
378 
380  int getReadTimeoutMs();
381 
382 
384  date getReadTimeoutDate();
385 
386 
388  setConnectTimeout(timeout to);
389 
390 
392  int getConnectTimeoutMs();
393 
394 
396  date getConnectTimeoutDate();
397 
398 
400 
412  hash sendMessage(MailMessage::Message message);
413 
414 
416 
418  forceDisconnect();
419 
420 
422 
431  nothing clearWarningQueue();
432 
433 
435 
465  nothing setWarningQueue(int warning_ms, int warning_bs, Queue queue, auto arg, timeout min_ms = 1s);
466 
467 
469 
487  hash getUsageInfo();
488 
489 
491 
500  clearStats();
501 
502 
504  // don't reimplement this method; fix/enhance it in the module
505 
506 private:
507  final disconnectIntern();
508 public:
509 
510 
511 
512 private:
513  log(string msg);
514 public:
515 
516 
517 
518 private:
519  logDbg(string msg);
520 public:
521 
522 
523 
524 private:
525  connectIntern();
526 public:
527 
528 
529 
530 private:
531  loginIntern();
532 public:
533 
534 
535  // send data over the socket
536 
537 private:
538  sendDataIntern(data str);
539 public:
540 
541 
542  // send data and log in the debug log if set
543 
544 private:
545  sendData(string str);
546 public:
547 
548 
549  // send data and log in the debug log if set
550 
551 private:
552  sendData(binary b);
553 public:
554 
555 
556  // send a command over the socket and return the response as a hash
557  // don't reimplement this method; fix/enhance it in the module
558 
559 private:
560  final hash sendCommand(string str);
561 public:
562 
563 
564  // read a line from the socket (terminated with \n)
565 
566 private:
567  string readLine(timeout to);
568 public:
569 
570 
571  // sends the message header (without body & attachments) to the SMTP server
572  // don't reimplement this method; fix/enhance it in the module
573 
574 private:
575  final hash sendMessageInfoIntern(MailMessage::Message message);
576 public:
577 
578 
579 
580 private:
581  forceDisconnectIntern();
582 public:
583 
585  };
586 
588 
595 
596 public:
598 
605  constructor(string name, string desc, string url, bool monitor, *hash opts, hash urlh) ;
606 
607 
609  string getType();
610 
611 
613 
618 
619 
621 
629 private:
630  SmtpClient getImpl(bool connect = True, *hash rtopts);
631 public:
632 
633 
635  static SmtpConnection make(string name, string desc, string url, bool monitor, *hash opts, hash urlh);
636  };
637 };
*hash getRuntimeOptions()
returns runtime options
date date(date dt)
SmtpClient getImpl(bool connect=True, *hash rtopts)
returns an SmtpClient object
const True
constructor(string name, string desc, string url, bool monitor, *hash opts, hash urlh)
creates the SmtpConnection object
binary binary()
const DefaultReadTimeout
15 second read timeout
Definition: SmtpClient.qm.dox.h:163
const DefaultConnectTimeout
30 second connect timeout
Definition: SmtpClient.qm.dox.h:166
const False
class for SMTP connections; returns an object of class SmtpClient for sending emails ...
Definition: SmtpClient.qm.dox.h:594
string getType()
returns "smtp"
for backwards-compatibility only
Definition: SmtpClient.qm.dox.h:185
static SmtpConnection make(string name, string desc, string url, bool monitor, *hash opts, hash urlh)
static constructor
for backwards-compatibility and convenience
Definition: SmtpClient.qm.dox.h:169
the SmtpClient namespace holds all public definitions in the SmtpClient module
Definition: SmtpClient.qm.dox.h:161
constructor(string sender, string subject)
creates a Message object from the arguments given; this variant of the constructor is designed to be ...
hash hash(object obj)