Sending mail
Mail from Abacus is sent by the abasyn service on the server. Sklad only puts the message into a queue in the database, so workstations need no mail settings: one sender mailbox for the whole company, configured once in the abasyn configuration.
This queue carries:
- the Відправити документ поштою (send document by mail) toolbar button in Sklad;
- Службове → Відправити лист автору (write to the author);
- Поштова розсилка (mass mailing);
- notifications on the Пошта channel (Довідники → Працівники, tab Сповіщення): new order, Z-report, cash handover.
Until abasyn is configured, Sklad accepts messages without any error and they simply pile up in the queue. Once it is configured, abasyn sends everything that has accumulated.
Before you start
- abrest and abasyn are running on the server and the services are activated in Sklad - the same as for webshop sync.
- A mailbox to send from. Gmail is used as the example below.
- abasyn has TLS support: the
tlsfield in the service status is notunavailable(see "Verification"). Without it Gmail and most mail services refuse the connection. On Linux this needs thelibssl3package; on Windows it is installed with the services.
Gmail: app password
The ordinary Google account password does not work here - you need an app password.
- Sign in to the Google account the mail will be sent from.
- Security → 2-Step Verification - turn it on if it is not on yet. App passwords are unavailable without it.
- Open https://myaccount.google.com/apppasswords, enter a name such as
Abacusand press Create. - Google shows a 16-letter password in groups of four. Copy it without the spaces - it will not be shown again.
In Google Workspace the app password page may be disabled by the domain administrator - then it has to be enabled in the Admin console.
Changing the Google account password revokes every app password. Mail then stops with an authentication error - create a new app password and put it in the configuration.
Configuring abasyn
The configuration is the abasyn.yaml file:
- Linux:
/etc/abacus/abasyn.yamlor/opt/abacus/etc/abasyn.yaml; - Windows:
C:\ProgramData\Abacus\Conf\abasyn.yaml.
Add a mail block to it (the full commented list is in
abasyn.yaml.example next to the program):
mail:
enabled: true
host: smtp.gmail.com
port: 587
username: 'shop@gmail.com'
password: 'abcdefghijklmnop'
from_addr: 'shop@gmail.com'
from_name: 'My Shop'
| Field | Meaning |
|---|---|
enabled |
true turns sending on. |
host, port |
Mail server. For Gmail - smtp.gmail.com, port 587. |
tls |
Encryption: auto (default - 465 encrypted from the start, other ports via STARTTLS), starttls, implicit, none. Leave it out for Gmail. |
username, password |
Gmail address and app password. |
from_addr |
Sender address. Required: without it no message goes out. For Gmail - the same as username, or an address added in Gmail under Send mail as; Gmail replaces any other with the account address. |
from_name |
Sender name the recipient sees. |
interval |
How often abasyn checks the queue, seconds. Default 60. |
dry_run |
true - rehearsal: abasyn logs what it would send but sends nothing and leaves the queue untouched. |
max_attempts |
How many times to retry a message after a temporary error before marking it failed. Default 5. |
backoff_base, backoff_cap |
Pause before the first retry and the longest pause, seconds. Defaults 60 and 3600: pauses of 1, 2, 4... minutes, never longer than an hour. |
After changing the file, restart abasyn:
On Windows - the abasyn service in Services, or sc stop abasyn and
sc start abasyn as administrator.
Verification
$KEY is the abasyn API key.
1. Service status.
tlsmust not beunavailable;intervalseconds after start,Mailappears inworkerswith statusOK. If it is missing,enabledis nottruein the configuration, or abasyn has not re-read the file.
2. Test message. In Sklad, Службове → Відправити лист автору, put your own address in Одержувач (recipient) - one other than the sender mailbox - fill in subject and text, and send. Gmail files a message to yourself under Sent only, not in the Inbox.
3. Skip the one-minute wait. To make abasyn check the queue right away:
4. Result.
- The message arrived. If not, check the Spam folder.
- The abasyn log has the line
Notify runner: mail dispatch ok: {... "sent" : 1 ...}. - The same summary shows in
last_statsof themailjob:
5. Message with an attachment. Open any document whose counterparty has an e-mail (or change the recipient to your own address), press Відправити документ поштою, choose a print template. A message with the document as XLS should arrive.
To get acquainted without real messages, set dry_run: true first: the log
shows Notify dry-run: would send id N over mail, and the messages stay queued
until the rehearsal is turned off.
The mail queue
Each message is a row in the S_NOTIFY_QUEUE table with CHANNEL = 'mail',
one row per notification recipient. The STATUS field:
STATUS |
Meaning |
|---|---|
Q |
Queued. If ATTEMPTS is above zero there were temporary errors already; the next attempt follows a pause. |
S |
Sent. |
F |
Finally not sent. The reason is in LAST_ERROR. |
An error counts as final when retrying will not fix it: a wrong recipient
address, a message rejected by the server, a damaged attachment. Such a message
gets F at once. Temporary errors (server unreachable, dropped connection) are
retried up to max_attempts times.
A wrong login or password, missing TLS or an unreachable server do not spoil
the queue: abasyn cannot open a session, logs the error and shows it in the
Mail status, and the messages stay Q and go out as soon as the problem is
fixed.
To resend messages that got F (for example after hitting the Gmail daily
limit):
Gmail limits
- A regular Gmail account sends to up to 500 recipients a day, Google
Workspace up to 2000. After that Gmail rejects messages until the day ends,
and they get
Fwith a quota error. Mass mailing to a large customer base is the easiest way to hit the limit. - Sklad refuses attachments over 10 MB before they reach the queue.
Common problems
| Symptom | Cause and fix |
|---|---|
SMTP authentication rejected for ...: 535 ... |
The ordinary Google password was entered instead of an app password, or the app password was revoked by an account password change. Create a new app password. |
SMTP login failed, and the service status shows tls: unavailable |
abasyn has no TLS. On Linux install libssl3 and restart abasyn; on Windows reinstall the services. |
invalid sender address |
from_addr is empty or wrong. |
unknown mail tls mode |
Wrong value in tls. |
Unknown mail type |
Wrong value in type; it can be left out. |
failed to fetch the mail outbox |
abasyn cannot get the queue from abrest: abrest is not running or the services are not activated. |
The message came from the account address, not from_addr |
Gmail replaces a sender that is not listed under Send mail as in Gmail settings. |
Mail is missing from the service status |
enabled is not true, or abasyn was not restarted after the file changed. |
Messages stay Q, nothing in the log |
Same: sending is off. An empty queue is not logged, so silence with sending on means there are no messages. |