Switch language to english
Znuny Professional Services

Der ((OTRS)) Community Edition Fork mit Langzeit-Support (LTS)

Mastering Znuny CLI: Mail Filters and Routing Testing

In the realm of system administration, efficiency is paramount. Embracing the power of the command line interface (CLI) can be a game-changer for administrators. Not only does it offer speed and resource efficiency, but it also provides a robust platform for scripting and automation. In this guide, we delve deeper into the world of Znuny CLI, focusing on testing mail filters and routing. Discover how this versatile tool can streamline your operations and elevate your administration prowess.

In the previous article, we discussed using postmaster filters to match information and add this to the ticket. I want to go further into this topic and discuss testing and general considerations for administrators using the Console.pl, command.

Why the Command Line

Often, administrators prefer access via the command line. Administrators may choose to use the command line interface (CLI) for several reasons:

  • Efficiency and Speed:
    Experienced administrators often find it faster to perform tasks via the command line. Once you become proficient, typing out commands can be quicker than navigating through graphical user interfaces (GUIs).

  • Scripting and Automation:
    CLI allows for easy scripting and automation of tasks. This is critical for tasks that must be repeated regularly or for managing large numbers of systems simultaneously.

  • Resource Efficiency:
    CLI tools tend to be lighter regarding system resource usage than GUI.

  • Remote Management:
    Many server environments, especially in professional settings, are administered remotely via SSH (Secure Shell) or similar protocols. The CLI is the natural interface for these scenarios.

  • Script Portability:
    CLI scripts can often be easily transferred between different systems and operating systems, which is helpful in heterogeneous environments.

  • Debugging and Troubleshooting:
    When issues arise, the command line often provides more detailed and immediate feedback than a GUI. This can be crucial for diagnosing and resolving problems.

  • Resource Control:
    CLI allows for fine-grained control over system resources, which can be crucial when optimizing performance is critical.

  • Flexibility:
    CLI tools often provide more flexibility and options compared to their GUI counterparts. This can be essential for power users who must tailor their environment to specific requirements.

  • Version Control and Logging:
    Working in a text-based environment often makes it easier to track changes using version control systems and maintaining detailed logs of actions taken.

  • Security and Permissions:
    The command line can provide better access to resources the web server might not have.

Znuny CLI

The Znuny CLI is the script bin/znuny.Console.pl (bin/otrs.Console.pl for LTS 6.5 and older). For this console, there are dozens of commands. Some were discussed in the article Size does matter: When just one instance won't do!. We will look at the mail-related commands today. The following search can help you identify possible commands.

[otrs@example ~]$ bin/znuny.Console.pl Search Mail
Searching for commands similar to 'Mail'...
 Dev::Tools::ImportFakeEmails             - Insert fake emails/tickets to the system.
 Dev::Tools::TestEmails                   - Get emails from test backend and output them to screen.
 Maint::Email::MailQueue                  - Mail queue management.
 Maint::PostMaster::MailAccountFetch      - Fetch incoming emails from configured mail accounts.
 Maint::PostMaster::Read                  - Read incoming email from STDIN.
 Maint::PostMaster::SpoolMailsReprocess   - Reprocess mails from spool directory that could not be imported in the first place

We want to focus on the commands that will help us test mail filters and routing.

Using the CLI

It's mostly only possible to use the console in the context of the znuny (or Application User) user. This can be done by signing in as the znuny user.

su - znuny

Note: Your environment should be set so that the znuny user's home is the application directory, and the user's primary group is the web server group.

Once signed in, you can use the commands like this:

bin/znuny.Console.pl COMMAND NAME

To get help, use the --help option.

Processing Test Mails

If you are polling your mail from a mail account, you can selectively use the console to poll a mailbox during testing purposes. The mail account ID can be found in the administration area under Admin ⇒ PostMaster Mail Accounts.

bin/znuny.Console.pl Maint::PostMaster::MailAccountFetch  ----mail-account-id N

Adding --debug will give you valuable output.

Testing is also possible using local mail files. Some examples are
located under doc/sample-mails/. To achieve this, we use the following command.

`bin/znuny.Console.pl Maint::PostMaster::Read < doc/sample-mails/test-email-1.box

If you want to process multiple emails, then copy the files to be processed to var/spool/, then run the command:

`bin/znuny.Console.pl Maint::PostMaster::SpoolMailsReprocess

Any of these tools can help you process emails to test filters and routing of emails with minimum effort. We will talk about other commands later.