LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Server (https://www.linuxquestions.org/questions/linux-server-73/)
-   -   How to trigger a script for any incoming mail on delivery to mailbox (https://www.linuxquestions.org/questions/linux-server-73/how-to-trigger-a-script-for-any-incoming-mail-on-delivery-to-mailbox-4175628383/)

geoher 04-25-2018 05:58 AM

How to trigger a script for any incoming mail on delivery to mailbox
 
I have a non-public postfix mailserver intended to receive system mails.
To make the server dynamic, I would like it to react to unknown recipiants by creating their account (by running a script, or by other means).

My setup is on CentOS7, latest postfix and dovecot and MySQL "backend".
I was thinking about using procmail to filter and "trigger" on incoming mail.

I think I need to involve master.cf to get my "${data}" variables from the incoming mail (mail address, user, domain and so on). Feel free to suggest otherwise.
If I try to use a "pipe" in master.cf, postfix simply responds by realying the mail to the script, never delivering it to the recipant mailbox.

In my script i simply test if the user (mailadress) in the incoming mail is present in the postfix database. If not, it will create it. Dovecot will create the mail folders for any new virtual mail account. If the recipiant exist, a normal local mailbox relay should occur.
Preferably I would like the first mail to be delivered to the new mailbox too. Maybe by deferring?

Also, I need to trigger a mail to notify users of arrival of new mail to their account.
The users will only reach their messages on this system by a portal, and I want to notify the portal user with a standard mail to their preferred real mailaccount (not a forward of the incoming mail), like "You have a new message at xxx.xxx.com. Please login to read"

As mentioned, the server is located in a restricted zone and is intended for this purpose only, unreachable for other systems so do not worry about security at this point. Dovecot will simply provide an imap structure.

I would appriciate any tips on configs (or other solutions entirely) to get this working.

Thank's in advance,
GeoHer

RandomTroll 04-25-2018 09:41 AM

You may find better solutions, but I use inotify to respond to new webcam images at my site.

pan64 04-25-2018 12:02 PM

probably this helps: https://serverfault.com/questions/26...-debian#261199

geoher 04-25-2018 07:42 PM

Hello

Most solutions semes to be related to a single user and it’s $HOME folder.
I need a solution for all incoming mail to all users. All users are virtual and have no $HOME, only a maildir.

But thank’s anyway!

scasey 04-26-2018 09:13 AM

Quote:

Originally Posted by geoher (Post 5847260)
If I try to use a "pipe" in master.cf, postfix simply responds by realying the mail to the script, never delivering it to the recipant mailbox.

I would think that if you can get the mail relayed to the script, the script should be able to deliver it to the mailbox...but, isn't there going to (might) be an issue of that delivery being relayed to the script again, causing a loop?

While your problem description is fairly clear, I'm not clear on what problem you're trying to solve...why would you be receiving "system mails" addressed to "unknown recipients"? Surely you (or someone) has control of the addresses to which system emails are sent.

RandomTroll 04-26-2018 12:57 PM

inotify would work.


All times are GMT -5. The time now is 08:30 PM.