Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure Postfix to relay all incoming mails to my Python script Without checking if user exists on the system?

I want to configure my Postfix server as accepting all incoming mails to any arbitrary users who don't have to exist on the system, say [email protected]. Now Postfix says, User unknown in local recipient table. What I want is to accept this e-mail without rejecting it and pipe it to my python script. Any help would be gladly appreciated.

like image 547
Carlos Avatar asked May 30 '14 12:05

Carlos


People also ask

How do you configure SMTP Postfix mail in Linux?

Configuring Postfix All of the options you need for the service are located in /etc/postfix . The main configuration file for the Postfix service is located at /etc/postfix/main.cf . Within the configuration file, there are many options that you can add, some of them more common than others.

Can Postfix receive emails?

For installing Postfix server, your user should have sudo privileges (admin rights for installing postfix). If you want to receive emails from internet you should have DNS Records for Your Mail Server. You need to make sure Port 25 is open so that Postfix can receive emails from other SMTP servers.


1 Answers

You can use

luser_relay - Optional catch-all destination for unknown `local(8)` recipients. 

Add the following to your main.cf.

#/etc/postfix/main.cf
#...
#...
mydestination = $myhostname, localhost.$mydomain, localhost, mydomain.com
local_recipient_maps =
luser_relay = catchall
alias_maps = hash:/etc/aliases
#...
#...

and the following to your aliases file.

#/etc/aliases
catchall:  |/path/to/your/python_script.py

Run the following commands

postalias /etc/aliases
service postfix reload

and you can test the setup by following command

echo "test email"|mail -s 'Test email' [email protected]

Emails to unknown users will be delivered to the python script. Hope that helps.

like image 128
clement Avatar answered Oct 05 '22 12:10

clement