This service ensures sending emails through SMPT the SMTP protocol. Service The service is launched from from D2000_EXE/bin64/smtp.exe directory (or in case of Linux: D2000_EXE/bin64/opt/d2000/bin/smtp).
Parameters of the command line
Parameters of the service are followingas follows:
- -c <connectionString> – binding address , on which where process D2Connector.exe listens to incoming JAPI connections. If the JAPI connection is encrypted, there will be a path to the file with a certificate following the semicolon. If a redundancy is used, it will be possible to enter a parameter multiple times and name all connection points. Examples of parameter value:
server.domain.sk:3120
172.16.1.3:3121
srvapp120v:3120;certifikat.crt - -w <applicationName> – optional name of the service, implicitly SELF(.EMS -EMail Service)
- --logDir <logging directory> - optional way to logging directory, the value is implicitly set on to a relative waypath
../loginto within the D2000 logging directory. If there is no directory on this relative waypath, it will be logged into the created directory ./login the work directory under which the process is running - --reconnectTimeout <number of seconds> - number of seconds during which the process tries to reconnect to D2Connector.exe, the implicit value is 10 seconds
Except Beside parameters set in the command line, it is also possible to configure also the JVM process itself, in which the service runs through smtp.cfg file, which must be located in the same directory - D2000_EXE/bin64/. It is possible to define parameters using using the documented Jar2Exe tool tool. For example, activating debugging of all network communication for JVM is possible by the following configuration of smtp.cfg.
| Blok kódu | ||
|---|---|---|
| ||
option -Djavax.net.debug=all |
...
The service publishes functionality through the following ESL interface:
| Blok kódu | ||||
|---|---|---|---|---|
| ||||
RPC PROCEDURE [_hTC, TC_B] OpenConnection(IN TEXT _host, IN INT _port, IN TEXT _defaultFrom, IN BOOL _enableSsl, IN TEXT _userName, IN TEXT _password, IN BOOL _disablePlainAuthenticationSend, IN TEXT _additionalProperties) RPC PROCEDURE [_hTC, TC_B] OpenConnectionFromProps(IN TEXT _properties) RPC PROCEDURE [_hTC, TC_C] SendMail(IN INT _mailId, IN TEXT _from, IN TEXT _to, IN TEXT _cc, IN TEXT _bcc, IN TEXT _subject, IN TEXT _body) RPC PROCEDURE [_hTC, TC_E] CloseConnection |
This interface is based on communication defined by applications. Communication is initiated by calling of the RPC method OpenConnection or alternatively alternatively OpenConnectionFromProps, by which the connection to the SMTP server is initiated. By Using the RPC method SendMail, email the email is send sent within the given communication. The end of the connection/communication is realized through the RPC method method CloseConnection. All calls of to methods are asynchronous. The client must implement the following interface on his its side, so they it can be notified of the state of his its calls:
| Blok kódu | ||||
|---|---|---|---|---|
| ||||
RPC PROCEDURE [_hTC, TC_C] OnConnectionOpened RPC PROCEDURE [_hTC, TC_E] OnConnectionClosed(IN BOOL _closedWithError, IN TEXT _errorMessage, IN TEXT _errorDetail) RPC PROCEDURE [_hTC, TC_C] OnMailSent(IN INT _mailId) RPC PROCEDURE [_hTC, TC_C] OnMailSendingFailed(IN INT _mailId, IN TEXT _errorMessage, IN TEXT _errorDetail) |
Opening of SMTP connection through the OpenConnection and OpenConnectionFromProps methods
OpenConnection method The OpenConnection method realizes a connection to the SMTP server through method parameters. Internally, email sending is realized through through the JavaMail library, which is configured through the a set of more than 50 configuration parameters. Most of them needs need to be explicitly set only in exceptional cases. That is why the RPC method OpenConnection has has only the most widely-used parameters, ; it is possible to define the rest through parameter the _additionalProperties parameter in .properties súborov formatfile format. Alternatively, it is possible to initiate a SMTP connection only through these settings by OpenConnectionFromProps method through text parameter _properties with following content:
...
Successful opening of SMTP connection through OpenConnection/OpenConnectionFromProps methods is notified by calling calling the OnConnectionOpened method within within I.SMTP_Client_v1 interface interface, which must the client must implement. Ending The end of the SMTP connection or its failure is notified through through OnConnectionClosed method.
...
SendMail method implements sending of emails. The first parameter _mailId is marked by the identifier of the email which filled the client while calling that the client filled out before calling the SendMail method. The client is notified of a success or a failure through OnMailSent a OnMailSendingFailed methods of interface I.SMTP_Client_v1.
Example of using the ESL interface for email sending
Following The following code represents the an example of a simple email service in an application. To send an email, it is enough to call the RPC procedure SendMail. Event E.MailService internally uses communication with SELF.EMS process that holds the communication open and, in the case of connection failure, restores it automatically. At the same time, all unsent emails will be stored in the container, so no email will be thrown away, all not yet sent emails will be stored in the bin. When reconnecting with SELF.EMS process, it tries to automatically send the emails again.
| Blok kódu | ||||
|---|---|---|---|---|
| ||||
IMPLEMENTATION I.SMTP_Client_v1 INT _hCnt, _hTC, _nextMailId BOOL _hasTC ; PoAfter nadviazaníestablishing spojeniaconnection sowith SMTP server, it serveromtries sato pokúsisend odoslaťall všetkynot doterazyet neodoslanésent mailyemails IMPLEMENTATION RPC PROCEDURE [_hTC, TC_C] I.SMTP_Client_v1^OnConnectionOpened RECORD NOALIAS (SD.MailData) _mail INT _count, _i _hasTC := @TRUE CNT_CNVTOARRAY _hCnt CNT_GETNR _hCnt, _count FOR _i = 1 TO _count DO_LOOP CNT_GETITEM _hCnt, _i, _mail CALL Internal_SendMail(_mail) END_LOOP END OnConnectionOpened IMPLEMENTATION RPC PROCEDURE [_hTC, TC_E] I.SMTP_Client_v1^OnConnectionClosed(IN BOOL _closedWithError, IN TEXT _errorMessage, IN TEXT _errorDetail) IF _closedWithError THEN LOGEX _errorMessage ENDIF CALL [_hTC] I.SMTP_Service_v1^CloseConnection _hasTC := @FALSE END OnConnectionClosed ; Pri úspešnom odoslaní mailu ho vymaže z kontajneruWhen the email is sent successfully, it deletes the mail from the container IMPLEMENTATION RPC PROCEDURE [_hTC, TC_C] I.SMTP_Client_v1^OnMailSent(IN INT _mailId) CNT_DELETE _hCnt, _mailId END OnMailSent ; Pri neúspešnom odoslaní mailu zaloguje chybu When the email is not sent successfully, it logs an error IMPLEMENTATION RPC PROCEDURE [_hTC, TC_C] I.SMTP_Client_v1^OnMailSendingFailed(IN INT _mailId, IN TEXT _errorMessage, IN TEXT _errorDetail) LOGEX _errorMessage END OnMailSendingFailed RPC PROCEDURE [_hTC, ERROR] OnConversationAborted _hasTC := @FALSE END OnConversationAborted ; NadviazanieEstablishing spojeniaconnection sowith SMTP serverom, ak už neexistujeserver, if it does not exist any more PROCEDURE Internal_InitConnection IF !_hasTC THEN CALL [(0)] I.SMTP_Service_v1^OpenConnection("mail.example.com", 25, "", @FALSE, "user", "secret", @FALSE, "") ASYNC ON SELF.EMS TC_B _hTC ENDIF END Internal_InitConnection PROCEDURE Internal_SendMail(IN RECORD NOALIAS (SD.MailData) _mail) TEXT _from _from := "no-reply@ipesoft.com" CALL [_hTC] I.SMTP_Service_v1^SendMail(_mail[1]^id, _from, _mail[1]^to, "", "", _mail[1]^subject, _mail[1]^message) ASYNC TC_C END Internal_SendMail ; When RPC volanáis called "zfrom vonkuoutside" RPC PROCEDURE SendMail(IN TEXT _to, IN TEXT _subject, IN TEXT _message) RECORD NOALIAS (SD.MailData) _mail _mail[1]^id := _nextMailId _mail[1]^to := _to _mail[1]^subject := _subject _mail[1]^message := _message CNT_INSERT _hCnt, _mail[1]^id, _mail _nextMailId := _nextMailId + 1 CALL Internal_InitConnection IF _hasTC THEN CALL Internal_SendMail(_mail) ENDIF END SendMail ; InicializačnáInitial časťpart - vytvorenie kontajnera creation of a container and a konverzáciecommunication BEGIN CNT_CREATE _hCnt _hasTC := @FALSE _nextMailId := 1 CALL Internal_InitConnection END |