Skip to main content

Sending Documents by Email - REST API

How to Send Documents Using REST API and SMTP Server?

Written by Lenka Haringerová

Via the REST API (as well as through the web interface), you can send a document by email.

For email sending to work, you need to configure a connection to an SMTP server.

Add the following values to the flexibee-server.xml file (on Linux, located in /etc/flexibee/flexibee-server.xml):

smtp.host

SMTP server address, typically localhost (the SMTP server runs on the same machine as ABRA Flexi Server)

smtp.port

SMTP server port, typically 25; optional

smtp.defaultFrom

Default sender email address

smtp.encryption

SMTP communication security mode:

noneno security (default)starttlssecure communication if supported by the server (STARTTLS command)tlsrequired switch to secure communication (TLS)sslfully secure communication (SSL)

smtp.auth.user

Login username, if the SMTP server requires authentication; optional

smtp.auth.password

Password; optional

Note:

If you need any additional configuration values, e.g. for SSL, please let us know.

Sending a document via the REST API on a correctly configured server requires a PUT (or POST) request to the URL /c/firma/faktura-vydana/1/odeslani-dokladu.xml with the following parameters:

?to=email@example.com

Recipient; multiple to parameters can be specified

?cc=email@example.com

CC (carbon copy); multiple cc parameters can be specified

?subject=Doklad ABC

Email subject

?sablona=code:SABLONA

&report-lang=en

Language of the PDF attachment

At least one recipient or CC recipient must be specified, and the subject is also required. The sender (From header) will be set to the current user performing the send, or the default value from the configuration.

The request body must contain the email body as plain text encoded in UTF-8. The email will be sent in both plain text and HTML format according to the template currently included in ABRA Flexi. We plan to support custom templates in the future.

The email will include a PDF attachment, and optionally an ISDOC version of the document.

Complete example of sending a document from the command line using the curl tool:

curl -k -L -u uzivatel:heslo -X PUT -d 'Dobrý den, zasíláme Vám slíbený dokument. S pozdravem ...' "https://localhost:5434/c/firma/faktura-vydana/1/odeslani-dokladu.xml?to=email@example.com&subject=Doklad%20ABC"

Note in particular the subject — as usual, parameters in the URL must be properly encoded.

Note:

You must provide either odeslani-dokladu.xml or the Accept: text/xml header.

Customizing Email Messages

In ABRA Flexi, you can customize outgoing messages in the following ways:

  • Text customization – you can edit the default text in the document type, which will be used when sending documents.

  • Template customization

Customizing the Email Message Template

The starting point is enabling the developer directory (developerDirectory).

The full description is lengthy, but we only need the part covering configuration and template customization:

  1. You need to edit flexibee-server.xml (where to find it?) and add <entry key="developerDirectory">/devel/</entry>CopyInstead of /devel/, enter the directory where the modification data will be stored (e.g. C:ProjectsFlexiBee).

  2. Restart ABRA Flexi

  3. In that directory, you need to create a folder called "default" (the so-called default instance — any other value only makes sense in a cloud environment) and within it a folder with the company identifier (the same as shown in the web interface). Alternatively, you can use the special identifier "!all" (without quotes).

  4. Copy the sample scripts into $developerDirectory/$instance/!all — the files relevant to us are located in the mail-templates directory.

Automatic Document Sending

ABRA Flexi supports automatic sending of all unsent documents that are marked for sending. These are documents that have the value "Send" set in the Mail Status field.

Sending can be triggered manually with the following command:

curl -H "Accept: application/xml" -u winstrom:winstrom -X PUT -L https://demo.flexibee.eu:5434/c/demo/faktura-vydana/automaticky-odeslat-neodeslane

Replace demo with the name of your instance in the cloud. If you are running Flexi on your own server, replace demo.flexibee.eu with the address of your server. Replace firma with the system name of your company in Flexi. You can find it, for example, in the URL when logging into the web interface.

__________________________________________________________________

Did this answer your question?