LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 01-20-2010, 01:00 PM   #1
Fredde87
Member
 
Registered: Aug 2005
Posts: 158

Rep: Reputation: 30
How do I get Postfix to deliver valid emails to maildir and relay remaining?


Hi,

I got a weird postfix setup question? This is a seperate server to the one I posted about earlier today.

I need to setup a postfix server which will accept emails for local know address (full addresses) and deliver them straight to the users maildir.

Any unknown addresses (however for the same domain), needs to be relayed to another server.

This is a bit of a special setup as there is no fixed internet connection to the server. So the plan is that local email get delivered straight away whilst emails to the same @domain, but that doesnt exist in the user tables get put in the hold queue and is later relayed to server number 2 when a connection is available.

I am using mysql to retrieve all my settings into postfix.


Appreciate the help!
 
Old 01-22-2010, 06:40 AM   #2
Dave_Devnull
Member
 
Registered: May 2009
Posts: 142

Rep: Reputation: 24
It should be achievable - I do something similar but never got round to 'finishing' it off entirely, but I hope this may be of some use to you: (reference to main.cf + standard sql .cf files which will be formed of the generic:

Code:
user = <database_username>
password = <database_password>
dbname = <database_name>
query = {THE QUERY TO GET THE DATA WANTED FOR A MATCH}
hosts = <database_host>

1. Does this server relay for this domain?
relay_domains = proxy:mysql:/etc/postfix/mysql/relay_domains.cf
{query = SELECT domain FROM domains WHERE domain='%s' AND local=0}
Code:
+----+---------------------------------+-------+
| Id | domain                          | local |
+----+---------------------------------+-------+
2. Does this server relay for this specific recipient
relay_recipient_maps = proxy:mysql:/etc/postfix/mysql/relay_recipients.cf
{query = select virtual_user_email from recipients where alias like '%u\@%d' and local=0}


How is it transported?
3.transport_maps = proxy:mysql:/etc/postfix/mysql/transport.cf
{query = SELECT transport FROM transport WHERE destination='%s'}
Code:
+----+---------------------------------+-----------+
| Id | destination                     | transport |
+----+---------------------------------+-----------+
|  1 | local.example.com               | virtual:  | 
|  2 | relay.example.com               | relay:    | 
{MORE AT: http://www.postfix.org/transport.5.html}
Go on to define local virtual domains, mailboxes and recipients with:

virtual_mailbox_domains = proxy:mysql:/etc/postfix/mysql/virtual_domains.cf
virtual_mailbox_maps = proxy:mysql:/etc/postfix/mysql/virtual_mailbox_recipients.cf
virtual_alias_maps = proxy:mysql:/etc/postfix/mysql/virtual_alias_maps.cf


I mostly had this working when I needed it, the key to making it work was having a 'local' flag in the database that determined if the domain/user was to be dropped locally or relayed on.

You'll probably get better answers from more professional and experiences users than me, but if it falls quite here try joining the postfix users mailing list and ask there {http://www.postfix.org/lists.html}. The users list is a little 'sharp' and be prepared for short, curt answers :-)

HTH
 
Old 01-22-2010, 07:28 AM   #3
Fredde87
Member
 
Registered: Aug 2005
Posts: 158

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by Dave_Devnull View Post
It should be achievable - I do something similar but never got round to 'finishing' it off entirely, but I hope this may be of some use to you: (reference to main.cf + standard sql .cf files which will be formed of the generic:

Code:
user = <database_username>
password = <database_password>
dbname = <database_name>
query = {THE QUERY TO GET THE DATA WANTED FOR A MATCH}
hosts = <database_host>

1. Does this server relay for this domain?
relay_domains = proxy:mysql:/etc/postfix/mysql/relay_domains.cf
{query = SELECT domain FROM domains WHERE domain='%s' AND local=0}
Code:
+----+---------------------------------+-------+
| Id | domain                          | local |
+----+---------------------------------+-------+
2. Does this server relay for this specific recipient
relay_recipient_maps = proxy:mysql:/etc/postfix/mysql/relay_recipients.cf
{query = select virtual_user_email from recipients where alias like '%u\@%d' and local=0}


How is it transported?
3.transport_maps = proxy:mysql:/etc/postfix/mysql/transport.cf
{query = SELECT transport FROM transport WHERE destination='%s'}
Code:
+----+---------------------------------+-----------+
| Id | destination                     | transport |
+----+---------------------------------+-----------+
|  1 | local.example.com               | virtual:  | 
|  2 | relay.example.com               | relay:    | 
{MORE AT: http://www.postfix.org/transport.5.html}
Go on to define local virtual domains, mailboxes and recipients with:

virtual_mailbox_domains = proxy:mysql:/etc/postfix/mysql/virtual_domains.cf
virtual_mailbox_maps = proxy:mysql:/etc/postfix/mysql/virtual_mailbox_recipients.cf
virtual_alias_maps = proxy:mysql:/etc/postfix/mysql/virtual_alias_maps.cf


I mostly had this working when I needed it, the key to making it work was having a 'local' flag in the database that determined if the domain/user was to be dropped locally or relayed on.

You'll probably get better answers from more professional and experiences users than me, but if it falls quite here try joining the postfix users mailing list and ask there {http://www.postfix.org/lists.html}. The users list is a little 'sharp' and be prepared for short, curt answers :-)

HTH
Hi Dave_Devnull,

Thank you very much for your reply. That seems to be almost exactly what I am after. However what I dont really understand is how the transport_maps work. The domain/email address in here is the recepients, and I understand from the guides I have read that I need a wildcard charecter for external emails? But I dont really understand how the mysql query is going to return that wild card if it is trying the match the row depending on the recipient?
 
Old 01-22-2010, 07:37 AM   #4
Dave_Devnull
Member
 
Registered: May 2009
Posts: 142

Rep: Reputation: 24
I recall I had it all working, but there was something wrong with the transport map set up. My notebook ends at that point which is really frustrating, but I seem to recall adding the transport map 'broke' it.

AFAIR I was looking for a way to define the transport on a per recipient basis, but I'm not sure it was necessary. Prior to that I had no custom transport declaration if my memory serves me correctly.

I appreciate this is not a great deal of help, and I'm waffling a bit here, but it's in the right ball park :-)
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Script to backup Maildir emails within home areas GuyWood13 Programming 7 04-17-2008 06:12 AM
Postfix: drop relay access denied emails zaheer99 Linux - Server 1 01-17-2008 03:45 AM
Postfix won't deliver to Maildir :-( Paulsuk Linux - Server 4 12-03-2007 03:15 PM
Postfix as a mail relay (getting relay access denied) hypexr Linux - Software 3 09-13-2005 07:15 PM
postfix/procmail doesn't deliver emails! eisman Ubuntu 1 05-18-2005 09:21 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 12:37 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration