Purpose: Shared DDD Infrastructure: generic emailing service
- this unit is a part of the freeware Synopse mORMot framework, licensed under a MPL/GPL/LGPL tri-license; version 1.18
Unit Name | Description | |
---|---|---|
dddDomUserInterfaces | Shared DDD Domains: User interfaces definition | |
dddDomUserTypes | Shared DDD Domains: User objects definition | |
dddInfraEmail | Shared DDD Infrastructure: implement an email validation service | |
mORMot | Common ORM and SOA classes for mORMot | |
mORMotDDD | Domain-Driven-Design toolbox for mORMot | |
SynCommons | Common functions used by most Synopse projects | |
SynCrtSock | Classes implementing TCP/UDP/HTTP client and server protocol | |
SynLog | Logging functions used by Synopse projects | |
SynMustache | Logic-less mustache template rendering | |
SynTable | Filter/database/cache/buffer/security/search/multithread/OS features | |
SynTests | Unit test functions used by Synopse projects |
Objects | Description | |
---|---|---|
ISMTPServerConnection | Used to inject the exact SMTP process to TDDDEmailerDaemon | |
TDDDEmailerDaemon | Daemon used to send emails via SMTP | |
TDDDEmailerDaemonProcess | Thread processing a SMTP connection | |
TDDDEmailerDaemonStats | Statistics about a TDDDEmailerDaemon instance | |
TDDDTemplateAbstract | Abstract Mustache-Based templating | |
TDDDTemplateFromFolder | Mustache-Based templating from a local folder | |
TSMTPServer | Abstract class used to resolve ISMTPServerConnection | |
TSMTPServerSocketConnection | Implements ISMTPServerConnection using SynCrtSock's low-level SMTP access | |
TSMTPServerSocketConnectionAbstract | Implements an abstract ISMTPServerConnection class | |
TSQLRecordEmailer | ORM class for email validation process |
ISMTPServerConnection = interface(IInvokable)
Used to inject the exact SMTP process to TDDDEmailerDaemon
function SendEmail(const aRecipient: TRawUTF8DynArray; const aSender,aSubject,aHeader,aBody: RawUTF8): RawUTF8;
This method should send the email, returning an error message on issue
- if no header is supplied, it will expect one UTF-8 encoded text message
TSMTPServer = class(TInterfaceResolverForSingleInterface)
Abstract class used to resolve ISMTPServerConnection
- see TSMTPServerSocket for actual implementation
constructor Create(aImplementation: TInterfacedObjectClass; aParameters: TSMTPServer); overload;
Initialize the class with the parameters of another TSMTPServer
instance
- in fact, TSMTPServer
could be used as parameter storage of its needed published properties, e.g. in a TApplicationSettingsAbstract sub-class
constructor Create(aImplementation: TInterfacedObjectClass; const aAddress: RawUTF8; aPort: cardinal; const aLogin,aPassword: RawUTF8); overload;
Initialize the class with the supplied parameters
procedure SetDefaultValuesIfVoid;
Will fill some default values in the properties, if none is set
- i.e. 'dummy:dummy@localhost:25'
TSMTPServerSocketConnectionAbstract = class(TInterfacedObject)
Implements an abstract ISMTPServerConnection
class
TSMTPServerSocketConnection = class(TSMTPServerSocketConnectionAbstract)
Implements ISMTPServerConnection
using SynCrtSock
's low-level SMTP access
TDDDEmailerDaemonStats = class(TSynMonitorWithSize)
Statistics about a TDDDEmailerDaemon
instance
- in addition to a standard TSynMonitor
, will maintain the connection count
procedure NewConnection;
Will increase the connection
count
property Connection: cardinal read fConnection;
The connection
count
TDDDEmailerDaemonProcess = class(TDDDMonitoredDaemonProcessRest)
Thread processing a SMTP connection
TDDDEmailerDaemon = class(TDDDMonitoredDaemon)
Daemon used to send emails via SMTP
- it will maintain a list of action in a TSQLRecordEmailer
ORM storage
function SendEmail(const aRecipients: TRawUTF8DynArray; const aSender,aSubject,aHeaders,aBody: RawUTF8): TCQRSResult;
This is the main entry point of this service
- here the supplied message body is already fully encoded, as expected by SMTP (i.e. as one text message, or multi-part encoded)
- if no header is supplied, it will expect one UTF-8 encoded text message
property RestClass: TSQLRecordEmailerClass read fRestClass;
The associated class TSQLRecordEmailer
used for status persistence
- any class inheriting from TSQLRecordEmailer
in the Rest.Model will be recognized by TDDDEmailerDaemon
to store its information
property SMTPServer: TSMTPServer read fSMTPServer write fSMTPServer;
The associated class used as actual SMTP client
TSQLRecordEmailer = class(TSQLRecordTimed)
ORM class for email validation process
- we do not create a whole domain here, just an ORM persistence layer
class procedure InitializeTable(Server: TSQLRestServer; const FieldName: RawUTF8; Options: TSQLInitializeTableOptions); override;
Will create an index on State
+ID
TDDDTemplateAbstract = class(TCQRSService)
Abstract Mustache-Based templating
TDDDTemplateFromFolder = class(TDDDTemplateAbstract)
Mustache-Based templating from a local folder
TSQLRecordEmailerState = ( esPending, esSending, esSent, esFailed );
State machine used during email validation process
Functions or procedures | Description | |
---|---|---|
TestDddInfraEmailer | You can call this function within a TSynTestCase class to validate the email validation via a full regression set |
procedure TestDddInfraEmailer(serverClass: TSQLRestServerClass; test: TSynTestCase);
You can call this function within a TSynTestCase
class to validate the email validation via a full regression set
- could be used as such:
procedure TTestCrossCuttingFeatures.Emailer; begin // TSQLRestServerDB is injected to avoid any dependency to mORMotSQLite3 TestDddInfraEmailer(TSQLRestServerDB,self); end;