Postfix message received hook
Asked Answered
B

2

6

I am writing an web-application which needs to receive e-mail messages to users' internal email addresses, let administrators approve them, and then forward to corresponding user's external mailbox.

I have installed and configured postfix for message receiving task. It uses virtual e-mail addresses, and my existing database where user email addresses are stored. Local email storage is maildir and I use postfix's virtual MDA.

Basically, I would like to execute a script every time a new message is received, and for which user (maildir message id would be very helpful too). Then I could read the message from python code (python had a module for maildir messageboxes) and insert it in database. I can think of three ways to do this:

  • iterate user maildirs and check if there are any new messages, but it would be ineffective for large number of users.
  • use dbmail and then check if there are any new messages in database (this would be quicker, but I'd have to configure everything from scratch). Besides, existing user data tables cannot be used.
  • write a wrapper around maildrop/virtual to save message in db and in maildir as well, but I'd need a way to check if received message is valid and successfully saved by the real MDA.

Any suggestions appreciated!

Barolet answered 22/11, 2009 at 12:22 Comment(0)
B
5

In response to my own question, I used postfix content_filter with X flag set in pipe and process receiving address and message manually. Since I didn't need to access messages in maildir, this approach works fine for me.

Barolet answered 22/11, 2009 at 15:12 Comment(0)
F
8

In the /etc/aliases file you can specifiy a program which gets executed everytime a user recieves a mail. This program gets the mail on stdin. So you dont have to poll and your program gets run instantly.

Flue answered 22/11, 2009 at 12:26 Comment(1)
This would be nice approach, but I'm using virtual relay mechanism.Barolet
B
5

In response to my own question, I used postfix content_filter with X flag set in pipe and process receiving address and message manually. Since I didn't need to access messages in maildir, this approach works fine for me.

Barolet answered 22/11, 2009 at 15:12 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.