Via the REST API — just like through the web interface — you can send a document by email. For sending to work, a connection to an SMTP server must be configured on the server.
SMTP server configuration
In the file flexibee-server.xml (on Linux in /etc/flexibee/flexibee-server.xml, where to find it), add the following values:
Value | Meaning |
| The SMTP server address, typically |
| The SMTP server port, typically 25. Optional. |
| The default sender email address. |
| The security mode for SMTP communication — see the values in the table below. |
| The login username, if the SMTP server requires authentication. Optional. |
| The password. Optional. |
Values for the smtp.encryption parameter:
| No security (default). |
| Secure communication if supported by the server (STARTTLS command). |
| Required switch to secure communication (TLS). |
| Fully secure communication (SSL). |
💡 In the cloud, where you don't have access to the flexibee-server.xml file, SMTP can also be configured via the REST API for an individual company — see SMTP server configuration - API.
Sending a document
On a properly configured server, sending a document means calling the PUT or POST method on the odeslani-dokladu sub-record:
PUT https://demo.flexibee.eu/c/demo/faktura-vydana/1/odeslani-dokladu.xml?to=email@example.com&subject=Doklad%20ABC
Parameter | Meaning |
| Recipient; this parameter can be specified multiple times. |
| CC; this parameter can be specified multiple times. |
| The email subject. |
| Custom email template — the ID of a record from the |
| The language of the PDF attachment. If not specified, the default email language is used. |
At least one recipient or CC recipient must be specified — otherwise the API returns 400 with code recipientIsMissing and the message At least one recipient must be specified. The sender (the From header) will be the current user account under which you are performing the sending, or otherwise the default value from the configuration.
The request body may contain the plain-text body of the email, encoded in UTF-8. The email will include the PDF version of the document as an attachment, and the ISDOC version as well, if applicable.
ℹ️ Either the odeslani-dokladu.xml extension or the Accept: text/xml header must be specified. Parameters in the URL must be correctly encoded — pay particular attention to the subject in the example above.
Where the email text comes from
Both the subject and the body are looked up in the following order — the first source with non-empty text is used:
The
subjectparameter, or the request body. Text consisting only of whitespace characters is not used.The template from the
sablonaparameter.The template from the document type.
The text from the document type.
The default template for the given record type.
The default system text.
Customizing email messages
Sent messages can be customized in two ways:
Text customization — you can set a default text in the document type that will be used when sending documents. Custom templates are managed via the
sablona-mailrecord type; see Custom email templates in the REST API.Template customization — described in the next section.
Customizing the email message template
The basis for this is enabling the developer directory (developerDirectory). The full description is quite long; here we're only interested in setting it up and then modifying the template:
In the file
flexibee-server.xml(where to find it?), add an entry with the directory where the modification data will be stored:<entry key="developerDirectory">/devel/</entry>Restart ABRA Flexi.
In that directory, create a directory named
default— the so-called default instance; any other value only makes sense in a cloud deployment — and inside it, create a directory with the company identifier that matches the one used in the web interface. Alternatively, you can use the special identifier!all.Copy the sample scripts into
$developerDirectory/$instance/!all; the important files are those in themail-templatesdirectory.
Automatic sending of documents
ABRA Flexi supports automatically sending all documents that have not yet been sent but are marked for sending — i.e., those whose stavMailK property has the value stavMail.odeslat (in the application, the Mail status field = Send). Other possible values are stavMail.neodesilat and stavMail.odeslano.
Sending can be triggered manually by calling:
PUT https://demo.flexibee.eu/c/demo/faktura-vydana/automaticky-odeslat-neodeslane
Accept: application/xml
🚨 This call sends emails for all documents marked for sending at once, so make sure you know in advance how many documents this affects — for example, by using the /c/{firma}/faktura-vydana.json?detail=custom:kod,stavMailK&filter=stavMailK%20eq%20'stavMail.odeslat' query.
Instead of demo, enter the system name of your company — you can find it, for example, in the URL after logging into the web interface. If you're running Flexi on your own server, use your server's address instead of demo.flexibee.eu.
