1

Topic: How do run the script using iRedMail?

Hello everyone,

I use iRedMail 1.7.1, and I want to run a simple script "test.sh" when I receive an email from the sender thomas2024@mail.com
I tried to do this using Procmail, but it's a bad solution because it complicates the system, and I didn't succeed as a result.
Can you tell me how to solve this problem using the capabilities of the iRedMail itself? (without adding additional utilities)

----

Spider Email Archiver: On-Premises, lightweight email archiving software developed by iRedMail team. Supports Amazon S3 compatible storage and custom branding.

2 (edited by Cthulhu 2025-03-02 21:14:07)

Re: How do run the script using iRedMail?

you can do the following:

1)
You need to enable sieve_extprograms in your dovecot config:

plugin {
  sieve_plugins = sieve_extprograms
  sieve_extensions = +vnd.dovecot.pipe
}

2)
You need to create a pipe config file

/etc/dovecot/custom-pipe.conf

In this file, you need to set the script directory

plugin {
  sieve_pipe_bin_dir = /var/lib/dovecot/custom-pipe
}

3)
create direcoty and ownership

mkdir -p /var/lib/dovecot/custom-pipe
chmod 750 /var/lib/dovecot/custom-pipe
chown dovecot:dovecot /var/lib/dovecot/custom-pipe

4)
create shellscript and give ownership/make it executable

/var/lib/dovecot/custom-pipe/myscript.sh
chmod +x /var/lib/dovecot/custom-pipe/myscript.sh
chown dovecot:dovecot /var/lib/dovecot/custom-pipe/myscript.sh

5)

modify the sieve script for that mailbox

require ["fileinto", "vnd.dovecot.pipe"];

if address "from" "thomas2024@mail.com" {
    pipe "/var/lib/dovecot/custom-pipe/myscript.sh";
}

3

Re: How do run the script using iRedMail?

i did not test this, but its nearly the same i use for spam/ham training and SHOULD work

4

Re: How do run the script using iRedMail?

Cthulhu, thank you so much for your attention to my problem!
I'm going to try your advice and tell you what happened.

5 (edited by Tamila 2025-03-02 22:08:17)

Re: How do run the script using iRedMail?

Cthulhu, позвольте мне задать несколько вопросов:

1)  Which file should I add this fragment to?

plugin {
  sieve_plugins = sieve_extprograms
  sieve_extensions = +vnd.dovecot.pipe
}

I added it to the end of the /etc/dovecot dovecot.conf file - is that correct?

5) Where exactly is the 'sieve script' located and what is its name?

6

Re: How do run the script using iRedMail?

the sieve script is in each users mail directory, or if you want it globally, it is

/var/vmail/sieve/dovecot.sieve

7

Re: How do run the script using iRedMail?

if you want it globally

But I do not know what I need to want, globally or not.
Which one is better?

Here is the mail directory:

/var/vmail/vmail1/extmail.info/i/a/2/ia2-2025.02.09.21.28.45/Maildir# ll
Total 96
drwx------ 2 vmail vmail  4096 Feb 28 19:17 cur
-rw------- 1 vmail vmail     0 Feb 28 09:22 dovecot-acl-list
-rw------- 1 vmail vmail   368 Feb 28 19:11 dovecot.index
-rw------- 1 vmail vmail 16848 Feb 28 19:16 dovecot.index.cache
-rw------- 1 vmail vmail 17972 Feb 28 19:18 dovecot.index.log
-rw------- 1 vmail vmail   264 Feb 28 11:44 dovecot.index.thread
-rw------- 1 vmail vmail   808 Feb 28 14:07 dovecot.list.index
-rw------- 1 vmail vmail  4352 Feb 28 19:11 dovecot.list.index.log
-rw------- 1 vmail vmail    96 Feb 28 09:22 dovecot.mailbox.log
-rw------- 1 vmail vmail   240 Feb 28 19:16 dovecot-uidlist
-rw------- 1 vmail vmail     8 Feb 28 09:22 dovecot-uidvalidity
-r--r--r-- 1 vmail vmail     0 Feb 28 09:22 dovecot-uidvalidity.67c1644e
drwx------ 2 vmail vmail  4096 Feb 28 19:17 new
-rw------- 1 vmail vmail    28 Feb 28 09:22 subscriptions
drwx------ 2 vmail vmail  4096 Feb 28 19:16 tmp

But unfortunately, I don't see a sieve script here. Where is it located and what is its name?

8

Re: How do run the script using iRedMail?

it is not in the maildir, it is one parent directory which is called sieve

local sieve scripts go there, if there is none you can create one with roundcube and then just modify it to your needs

9

Re: How do run the script using iRedMail?

local sieve scripts go there,

I don't understand where I need to go. Can you specify a specific path?

10

Re: How do run the script using iRedMail?

/var/vmail/vmail1/extmail.info/i/a/2/ia2-2025.02.09.21.28.45/sieve

11

Re: How do run the script using iRedMail?

Cthulhu, it seems I have followed all your advice.
However, my script does not run, and the logs contain the following errors:

sieve: info: started log at 2025-03-02 19:10:34 +0200.
managesieve: line 4: error: pipe command: invalid program name '/var/lib/dovecot/custom-pipe/test.sh'.
managesieve: error: validation failed.
sieve: info: started log at 2025-03-02 19:14:45 +0200.
managesieve: line 4: error: pipe command: invalid program name '/var/lib/dovecot/custom-pipe/test.sh'.
managesieve: error: validation failed.
sieve: info: started log at 2025-03-02 19:20:13 +0200.
managesieve: line 4: error: pipe command: invalid program name '/var/lib/dovecot/custom-pipe/test.sh'.

etc.
Why is this happening?


PS. My script 'test.sh':

#!/bin/bash
echo "An email was received from ia2 to ia2 in $(date)" >> /var/log/email_trigger.log

If I run it manually, it works fine.

12

Re: How do run the script using iRedMail?

invalid program name '/var/lib/dovecot/custom-pipe/test.sh'

is this the correct path?

13

Re: How do run the script using iRedMail?

Of course:

# ll
Total 4
-rwxr-xr-x 1 dovecot dovecot 97 Mar  2 19:48 test.sh
root@mail:/var/lib/dovecot/custom-pipe#

14 (edited by Cthulhu 2025-03-03 03:18:29)

Re: How do run the script using iRedMail?

you did restart dovecot, right? because if you do changes, they only take effect after restart

this error occours when sieve trys to execute external programms without beeing permitted by config

Edit: and i made an error, since sieve_pipe_bin_dir is set, don't give the full path, only the scriptname

pipe "test.sh";

15

Re: How do run the script using iRedMail?

plugin {
  sieve_plugins = sieve_extprograms
  sieve_global_extensions = +vnd.dovecot.pipe
}

16 (edited by Tamila 2025-03-03 04:31:04)

Re: How do run the script using iRedMail?

Of course, after the changes I always restarted Dovecot.


Now I made a replacement for pipe "test.sh";
but I got an error:

sieve: info: started log at 2025-03-02 22:16:33 +0200.
error: failed to pipe message to program `test.sh': refer to server log for more information. [2025-03-02 22:16:

Then I replaced
sieve_extensions = +vnd.dovecot.pipe
with
sieve_global_extensions = +vnd.dovecot.pipe

and after that other errors appeared in the logs:

sieve: info: started log at 2025-03-02 22:22:04 +0200.
error: failed to enable extension `vnd.dovecot.pipe': its use is restricted to global scripts.
managesieve: line 1: error: require command: failed to load Sieve capability `vnd.dovecot.pipe': its use is rest
managesieve: line 4: error: unknown command 'pipe' (only reported once at first occurrence).
managesieve: error: validation failed.

and letters stopped being delivered.

17

Re: How do run the script using iRedMail?

In general, all these options don't want to work.
Then I found this information on the Internet:

However, it is important to note that the standard Sieve does not support the execution of external scripts directly due to security issues.

Maybe this is the reason for the failures?

18

Re: How do run the script using iRedMail?

try this in global dovecot config instead:

plugin {
  sieve_plugins = sieve_extprograms
  sieve_global_extensions = +vnd.dovecot.pipe
  sieve_pipe_bin_dir = /var/lib/dovecot/custom-pipe
}

19

Re: How do run the script using iRedMail?

I inserted this fragment in /etc/dovecot/dovecot.conf - is this correct?

But when restarting Dovecot got an error:

# systemctl restart dovecot.service 
Job for dovecot.service failed because the control process exited with error code.
See "systemctl status dovecot.service" and "journalctl -xeu dovecot.service" for details.

and

journalctl -xeu dovecot.service
░░ Subject: Unit process exited
░░ Defined-By: systemd
░░ Support: https://www.debian.org/support
░░ 
░░ An ExecStart= process belonging to unit dovecot.service has exited.
░░ 
░░ The process' exit code is 'exited' and its exit status is 89.
Mar 03 14:00:02 mail systemd[1]: dovecot.service: Failed with result 'exit-code'.
░░ Subject: Unit failed
░░ Defined-By: systemd
░░ Support: https://www.debian.org/support
░░ 
░░ The unit dovecot.service has entered the 'failed' state with result 'exit-code'.
Mar 03 14:00:02 mail systemd[1]: Failed to start dovecot.service - Dovecot IMAP/POP3 email server.
░░ Subject: Error in the dovecot.service unit
░░ Defined-By: systemd
░░ Support: https://www.debian.org/support
░░ 
░░ The dovecot.service unit has crashed.

20

Re: How do run the script using iRedMail?

then it seems it did not load the previous config at all, and currently i have no clue why it doesnt work

21 (edited by Cthulhu 2025-03-03 20:38:38)

Re: How do run the script using iRedMail?

what does this show:

dovecot -n
journalctl -u dovecot --no-pager | tail -n 30

22

Re: How do run the script using iRedMail?

Unfortunately, I'm not well versed in the nuances of iRedMail
and I may make an unintended mistake in the actions that you recommend..
May be would it be more convenient for you to solve this do this task on your server?

23

Re: How do run the script using iRedMail?

I guess you need this tutorial instead:
https://docs.iredmail.org/pipe.incoming … cript.html

24

Re: How do run the script using iRedMail?

Thanks!
But if a specialist Cthulhu, have not been able to solve this problem, then I will certainly not be able to solve it too :-(

25

Re: How do run the script using iRedMail?

I've been studying this guide:
https://docs.iredmail.org/pipe.incoming … cript.html

It is dangerous and unreliable for the following reasons:
1. The database is being altered.
2. All mail is directed by macros by a different path.

All this may accidentally break the reliability of Postfix and iRedMail in general.

I have iRedMail working fine, and I don't want to jeopardize its work.

Please make a solution to this task using Sieve.
Such a solution are will safe.