Qore SmtpClient Module Reference 2.0
Loading...
Searching...
No Matches
SmtpClient.qm.dox.h
1// -*- mode: c++; indent-tabs-mode: nil -*-
3
4/* SmtpClient.qm Copyright 2012 - 2024 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 ) + DataProviderActionCatalog::getActionOptionFromFields(
37protected:
38 deprecated deprecated SmtpSendEmailRequestDataType::Fields - ("to", "subject", "body") ), "output_type": SmtpSendEmailResponseDataType, }); }; }
39 "port": SmtpPort,
40 "ssl": False,
41 "tls": False,
42 },
43 "smtps": {
44 "port": SmtpsPort,
45 "ssl": True,
46 "tls": False,
47 },
48 "smtptls": {
49 "port": SmtpsPort,
50 "ssl": False,
51 "tls": True,
52 },
53 "esmtp": {
54 "port": EsmtpPort,
55 "ssl": False,
56 "tls": False,
57 },
58 "esmtps": {
59 "port": SmtpsPort,
60 "ssl": True,
61 "tls": False,
62 },
63 "esmtptls": {
64 "port": EsmtpPort,
65 "ssl": False,
66 "tls": True,
67 },
68 };
69
70public:
71 }
72
74
81 constructor(string host, softint port, *code log, *code dbglog);
82
83
85
105 constructor(string url, *code log, *code dbglog);
106
107
109
111 destructor();
112
113
115
122 hash<auto> getInfo();
123
124
126 setInfoLogClosure(*code log);
127
128
130 setDebugLogClosure(*code log);
131
132
134
136 string getTarget();
137
138
140
144 tls(bool n_tls);
145
146
148 bool tls();
149
150
152
156 ssl(bool n_ssl);
157
158
160 bool ssl();
161
162
164
171 setUserPass(string n_user, string n_pass);
172
173
175 test(bool ns);
176
177
179 bool test();
180
181
183
187 connect();
188
189
191 bool isConnected();
192
193
195
197 disconnect();
198
199
201 setReadTimeout(timeout to);
202
203
205 int getReadTimeoutMs();
206
207
209 date getReadTimeoutDate();
210
211
213 setConnectTimeout(timeout to);
214
215
217 int getConnectTimeoutMs();
218
219
221 date getConnectTimeoutDate();
222
223
225
238 hash<auto> sendMessage(MailMessage::Message message);
239
240
242
244 forceDisconnect();
245
246
248
257 nothing clearWarningQueue();
258
259
261
297 nothing setWarningQueue(int warning_ms, int warning_bs, Queue queue, auto arg, timeout min_ms = 1s);
298
299
301
322 hash<auto> getUsageInfo();
323
324
326
335 clearStats();
336
337
339
355 setEventQueue(Qore::Thread::Queue queue, auto arg, *bool with_data);
356
357
359
371 setEventQueue();
372
373
375 // don't reimplement this method; fix/enhance it in the module
376protected:
377 final disconnectIntern();
378public:
379
380
381protected:
382 log(string msg);
383public:
384
385
386protected:
387 logDbg(string msg);
388public:
389
390
391protected:
392 connectIntern();
393public:
394
395
396protected:
397 loginIntern();
398public:
399
400
401 // send data over the socket
402protected:
403 sendDataIntern(data str);
404public:
405
406
407 // send data and log in the debug log if set
408protected:
409 sendData(string str);
410public:
411
412
413 // send data and log in the debug log if set
414protected:
415 sendData(binary b);
416public:
417
418
419 // send a command over the socket and return the response as a hash
420 // don't reimplement this method; fix/enhance it in the module
421protected:
422 final hash<SmtpResponseInfo> sendCommand(string str);
423public:
424
425
426 // read a line from the socket (terminated with \n)
427protected:
428 string readLine(timeout to);
429public:
430
431
432 // sends the message header (without body & attachments) to the SMTP server
433 // don't reimplement this method; fix/enhance it in the module
434protected:
435 final hash<auto> sendMessageInfoIntern(MailMessage::Message message);
436public:
437
438
439protected:
440 forceDisconnectIntern();
441public:
442
444}
445
448
449public:
451 const SPS_CONNECT = "connect";
452
454 const SPS_READ_HELLO = "read-hello";
455
457 const SPS_SEND_HELLO = "send-hello";
458
460 const SPS_READ_HELLO_REPLY = "read-hello-reply";
461
463 const SPS_STARTTLS = "starttls";
464
466 const SPS_READ_STARTTLS_REPLY = "read-starttls-reply";
467
469 const SPS_UPGRADE_TO_TLS = "upgrade-tls";
470
472 const SPS_LOGIN = "login";
473
475 const SPS_READ_LOGIN_REPLY = "read-login-reply";
476
478 const SPS_COMPLETE = "complete";
479
480protected:
482 hash<auto> info;
483
485 Socket sock();
486
488 AbstractPollOperation poller;
489
491 Mutex m();
492
494 string state;
495
497 bool goal_reached = False;
498
500 bool esmtp = False;
501
504
507
510
513
516
519
520public:
521
523 constructor(SmtpClient smtp);
524
525
527
529 string getGoal();
530
531
533
535 string getState();
536
537
539
542
543
545 *hash<SocketPollInfo> continuePoll();
546
547
548 abort();
549
550
552protected:
554public:
555
556
558
560protected:
561 bool getReply(reference<int> rcode, reference<string> rmsg);
562public:
563
564};
565
567
574
575public:
577 const ConnectionScheme = ...;
578
579
581
591 constructor(string name, string description, string url, hash<auto> attributes = {}, hash<auto> options = {})
592 ;
593
594
596
613 constructor(hash<auto> config, *hash<auto> attr) ;
614
615
617 string getType();
618
619
621
625 *hash<auto> getRuntimeOptions();
626
627
629
635 DataProvider::AbstractDataProvider getDataProvider(*hash<auto> constructor_options);
636
637
639
644
645
647
652
653
655
662 Qore::AbstractPollOperation startPollConnect(*Logger::LoggerInterface logger);
663
664
666protected:
668public:
669
670
672
679protected:
680 SmtpClient getImpl(bool connect = True, *hash<auto> rtopts);
681public:
682
683
685protected:
686 hash<ConnectionSchemeInfo> getConnectionSchemeInfoImpl();
687public:
688
689};
690
692
694class SmtpClientDataProvider : public DataProvider::AbstractDataProvider {
695
696public:
698 const ProviderInfo = ...;
699
700
703
704
705protected:
707 SmtpClient smtp;
708
709 const ChildMap = ...;
710
711
712public:
713
715 constructor(*hash<auto> options);
716
717
719 constructor(SmtpClient smtp);
720
721
722 string getName();
723
724
726 *string getDesc();
727
728
730 *list<hash<DataProviderSummaryInfo>> getChildProviderSummaryInfo();
731
732
734
736protected:
738public:
739
740
742
746protected:
747 *AbstractDataProvider getChildProviderImpl(string name);
748public:
749
750
752protected:
753 hash<DataProviderInfo> getStaticInfoImpl();
754public:
755
756};
757
759class SmtpClientSendEmailDataProvider : public AbstractDataProvider {
760
761public:
763 SmtpClient smtp;
764
766 const ProviderInfo = ...;
767
768
771
772
775
778
780 constructor(*hash<auto> options);
781
782
784 constructor(SmtpClient smtp);
785
786
788 string getName();
789
790
792
797protected:
798 auto doRequestImpl(auto req, *hash<auto> request_options);
799public:
800
801
803
805protected:
806 *AbstractDataProviderType getRequestTypeImpl();
807public:
808
809
811
813protected:
814 *AbstractDataProviderType getResponseTypeImpl();
815public:
816
817
819 hash<DataProviderInfo> getStaticInfoImpl();
820
821};
822
824class SmtpSendEmailAttachmentDataType : public HashDataType {
825
826public:
828 const Fields = ...;
829
830
833
834};
835
838
840class SmtpSendEmailRequestDataType : public HashDataType {
841
842public:
844 const Fields = ...;
845
846
849
850};
851
854
856class SmtpSendEmailResponseInfoDataType : public HashDataType {
857
858public:
859protected:
861 const Fields = ...;
862
863
864public:
865
868
869};
870
872class SmtpSendEmailResponseDataType : public HashDataType {
873
874public:
877
878};
879
882
884class SmtpClientDataProviderFactory : public AbstractDataProviderFactory {
885
886public:
887protected:
889 static Class cls = new Class("SmtpClientDataProvider");
890
892 const FactoryInfo = ...;
893
894
895public:
896
898
900protected:
901 hash<DataProviderFactoryInfo> getInfoImpl();
902public:
903
904
906
908protected:
909 hash<DataProviderInfo> getProviderInfoImpl();
910public:
911
912
914protected:
916public:
917
918};
919}
920
921namespace Priv {
922const SmtpWhiteLogo = ...;
923
924
925const SmtpBlackLogo = ...;
926
927};
The SMTP data provider factory.
Definition SmtpClient.qm.dox.h:884
hash< DataProviderFactoryInfo > getInfoImpl()
Returns static factory information without provider_info.
const FactoryInfo
Factory info.
Definition SmtpClient.qm.dox.h:892
static Class cls
Data provider type info.
Definition SmtpClient.qm.dox.h:889
Class getClassImpl()
Returns the class for the data provider object.
hash< DataProviderInfo > getProviderInfoImpl()
Returns static provider information.
Data provider implementing an API for sending email messages.
Definition SmtpClient.qm.dox.h:694
hash< DataProviderInfo > getStaticInfoImpl()
Returns data provider static info.
const ProviderInfo
Provider info.
Definition SmtpClient.qm.dox.h:698
constructor(*hash< auto > options)
Creates the object from constructor options.
*list< string > getChildProviderNamesImpl()
Returns a list of child data provider names, if any.
constructor(SmtpClient smtp)
Creates the object from an SmtpClient object.
SmtpClient smtp
The SmtpClient object.
Definition SmtpClient.qm.dox.h:707
*AbstractDataProvider getChildProviderImpl(string name)
Returns the given child provider or NOTHING if the given child is unknown.
*list< hash< DataProviderSummaryInfo > > getChildProviderSummaryInfo()
Return data provider summary info.
const ConstructorOptions
Constructor options.
Definition SmtpClient.qm.dox.h:702
*string getDesc()
Returns the data provider description.
Send email data provider.
Definition SmtpClient.qm.dox.h:759
string getName()
Returns the data provider name.
SmtpClient smtp
SMTP connection.
Definition SmtpClient.qm.dox.h:763
const ProviderInfo
Provider info.
Definition SmtpClient.qm.dox.h:766
constructor(SmtpClient smtp)
Creates the object from an SMTP connection.
hash< DataProviderInfo > getStaticInfoImpl()
Returns data provider static info.
auto doRequestImpl(auto req, *hash< auto > request_options)
Makes a request and returns the response.
const ProviderSummaryInfo
Provider summary info.
Definition SmtpClient.qm.dox.h:770
constructor(*hash< auto > options)
Creates the object from constructor options.
const RequestType
Request type.
Definition SmtpClient.qm.dox.h:774
*AbstractDataProviderType getResponseTypeImpl()
Returns the description of a response message, if this object represents a response message.
const ResponseType
Response type.
Definition SmtpClient.qm.dox.h:777
*AbstractDataProviderType getRequestTypeImpl()
Returns the description of a successful request message, if any.
class for SMTP connections; returns an object of class SmtpClient for sending emails
Definition SmtpClient.qm.dox.h:573
SmtpClient getImpl(bool connect=True, *hash< auto > rtopts)
returns an SmtpClient object
*hash< auto > getRuntimeOptions()
returns runtime options
constructor(hash< auto > config, *hash< auto > attr)
creates the SmtpConnection connection object
string getType()
returns "smtp"
bool hasDataProvider()
returns True, as the connection returns a data provider with the getDataProvider() method
bool supportsPollingApi()
returns True, since this connection type supports the Qore Socket-based polling API
DataProvider::AbstractDataProvider getDataProvider(*hash< auto > constructor_options)
returns an SmtpClientDataProvider object for this connection
setChildCapabilities()
Sets child data provider capabilities.
hash< ConnectionSchemeInfo > getConnectionSchemeInfoImpl()
Returns the ConnectionSchemeInfo hash for this object.
Qore::AbstractPollOperation startPollConnect(*Logger::LoggerInterface logger)
Called to start a non-blocking polling ping operation on the remote SMTP server.
const ConnectionScheme
Connection entry info.
Definition SmtpClient.qm.dox.h:577
constructor(string name, string description, string url, hash< auto > attributes={}, hash< auto > options={})
creates the SmtpConnection connection object
Class for SMTP non-blocking / polling pings.
Definition SmtpClient.qm.dox.h:447
string hello_reply
Server's HELO / EHLO reply.
Definition SmtpClient.qm.dox.h:506
const SPS_SEND_HELLO
Send hello state.
Definition SmtpClient.qm.dox.h:457
int starttls_code
Server's STARTTLS code.
Definition SmtpClient.qm.dox.h:509
const SPS_STARTTLS
Send STARTTLS state.
Definition SmtpClient.qm.dox.h:463
int login_code
Server's login code.
Definition SmtpClient.qm.dox.h:515
const SPS_COMPLETE
Complete state.
Definition SmtpClient.qm.dox.h:478
Socket sock()
The Socket for communication with the server.
bool goal_reached
Goal reached flag.
Definition SmtpClient.qm.dox.h:497
*hash< SocketPollInfo > continuePoll()
Returns a hash to be used for I/O polling or NOTHING in case the poll operation is complete.
string getGoal()
Returns the goal.
bool getReply(reference< int > rcode, reference< string > rmsg)
Private reads a reply from the SMTP server.
bool goalReached()
Returns True when the goal as been reached.
const SPS_READ_LOGIN_REPLY
Read login reply.
Definition SmtpClient.qm.dox.h:475
const SPS_CONNECT
Connect state.
Definition SmtpClient.qm.dox.h:451
string getState()
Returns the current state.
string login_reply
Server's login reply.
Definition SmtpClient.qm.dox.h:518
const SPS_READ_HELLO
Read hello state.
Definition SmtpClient.qm.dox.h:454
AbstractPollOperation poller
The current internal poll operation.
Definition SmtpClient.qm.dox.h:488
const SPS_READ_HELLO_REPLY
Read hello reply state.
Definition SmtpClient.qm.dox.h:460
int hello_reply_code
Server's HELO / EHLO reply code.
Definition SmtpClient.qm.dox.h:503
const SPS_UPGRADE_TO_TLS
Upgrade socket connection to TLS.
Definition SmtpClient.qm.dox.h:469
hash< auto > info
Info about the SMTP client.
Definition SmtpClient.qm.dox.h:482
startLogin()
Starts the polling login state.
constructor(SmtpClient smtp)
Creates the object based on the SmtpClient.
string starttls_reply
Server's STARTTLS reply.
Definition SmtpClient.qm.dox.h:512
const SPS_READ_STARTTLS_REPLY
Read STARTTLS reply.
Definition SmtpClient.qm.dox.h:466
const SPS_LOGIN
Login state.
Definition SmtpClient.qm.dox.h:472
string state
Current state.
Definition SmtpClient.qm.dox.h:494
Mutex m()
Lock for atomicity.
bool esmtp
ESMTP flag.
Definition SmtpClient.qm.dox.h:500
SMTP attachment type.
Definition SmtpClient.qm.dox.h:824
const Fields
Field descriptions.
Definition SmtpClient.qm.dox.h:828
constructor()
Creates the object.
SMTP send email request type.
Definition SmtpClient.qm.dox.h:840
constructor()
Creates the object.
const Fields
Field descriptions.
Definition SmtpClient.qm.dox.h:844
SMTP send email response data type.
Definition SmtpClient.qm.dox.h:872
constructor()
Creates the object.
SMTP send email response info type.
Definition SmtpClient.qm.dox.h:856
constructor()
Creates the object.
const Fields
Field descriptions.
Definition SmtpClient.qm.dox.h:861
const True
const False
date date(date dt)