5

I'm developing a web application that requires that a registered username be able to receive emails to:

<some-username>@<my-web-app>.com

I need a way to be able to process the email with Python once the system has verified the address is in the system.

Assuming you are using Postfix, how can you add a hook for Python to do some post processing, once an email is received?

NFicano
  • 163
  • 1
  • 6

2 Answers2

9

Create a pipe alias in the aliases file (e.g. /etc/aliases).

some-username@my-web-app.com |/path/to/somescript.py

And then use the normal Python stdlib modules to tear the message apart.

If you need multiple addresses to point to it then have them all aliased to the newly-created alias.

Ignacio Vazquez-Abrams
  • 45,939
  • 6
  • 79
  • 84
  • I definitely need to do some more research on mail servers - I completely underestimated their complexity. I'll assume your solution is correct though, and will follow up once I reached that point, thanks! – NFicano Nov 27 '10 at 06:13
  • Can you do this also for all emails and for all emails that have a specific domain? – Myzel394 Jan 26 '23 at 20:53
0

See this page that contains useful information for writing milters in Python.

adamo
  • 6,925
  • 3
  • 30
  • 58
  • 1
    milters, as much as I love them, are probably not the right tool for this job, as he's looking to accept the messages, not just filter them before delivery. I'd personally probably use either a .forward file or make it a postfix transport. – Sean Reifschneider Nov 27 '10 at 09:16
  • What he is looking for is definitely doable with Python in a milter context. I am doing similar stuff with MIMEDefang, which I did not recommend because he wants a Python interface. – adamo Nov 27 '10 at 13:21