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:

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
 Dev::Tools::ImportFakeEmails             - Insert fake emails/tickets to the system.
 Dev::Tools::TestEmails                   - Get emails from test backend and output them to screen.
Maint
 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.


Sign Up For Our Newsletter

Bleiben Sie auf dem Laufenden mit Expertentipps, Updates und Einblicken in das Servicemanagement und Znuny.

Sign up now
and stay up-to-date!

We use rapidmail to send our newsletter. When you subscribe, you consent to the entered data being forwarded to rapidmail. Please also see the GTC and data privacy statement.