Is it possible to trigger a shell script on incoming emails, can it be done without services like dovecot, postix, etc?

This question more is for learning purpose.

I’m exploring ways to develop a small email server (in + out).

I have a domain that points to my server as well as mx records and all that stuff…

I also have the open ports 25, 26, 110, 993, 995, 143, 465…

I’d like to activate a shell script on incoming email.

I have apache + php running without problem. I type my domain on a browser => I see my pages from anywhere. (that part is done).

I don’t exactly know where to start…

There is tons of stuff when I search

I tried dovecot , mailhog , exim but I’m having difficulty to get them up and running.

My question is more : “is there a way to listen to port x for emails => when a email arrives => execute a script (in the rawest form possible)” ?

Install docker and from that install a container already configured
that handle email
You just need to configured some variable like stmp , impa adrs etc …

The scope of setting up a mail server is likely outside the scope of this forum however if you utilize something such as Exim for your MTA you can utilize the pipe transport to run an arbitrary command as you see fit: 29. The pipe transport

Here is a rough example on StackOverflow which may help point you in the right direction: php - Mail Routing using pipe in Exim - Stack Overflow

@Jintor, if you are talking about local system mail messages, which can be read using the mail command provided by the mailx package then you might be able to do a grep of the appropriate mail file, but even that is risky.

Risky because your mail for the root account, for example, would be stored in /var/spool/mail/root - an ASCII text file. You could grep out whatever text strings you want and then take the appropriate action. The real reason it is risky is that you would have to delete the mail message out of the /var/spool/mail/root file; and in doing so other system messages that you may not be aware of may also be deleted.

An important point to make here is that the mail command and mailx commands can both ve used to send and read email, but they are not fully-featured email clients (MUAs).

If you just want to get email services up and running I can provide you with a decent Youtube video that you may want to watch over and over again because the guy who made the video is difficult to understand at times.

This is the Youtube link to the video:

I also have the instructions written up in a Word Doc, but do not know how to get it to you privately.

There is a little known control panel for Alma/CentOS linux, which can configure virtual hosts and all mail related things, without adding any extra packages.

After setup you can even delete it, because all it does is configure your system, it does not stay resident, very clean and easy: