LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 10-14-2010, 01:42 PM   #1
kipphudson
LQ Newbie
 
Registered: Feb 2008
Location: Pasco, WA
Posts: 2

Rep: Reputation: 0
Virtual Postfix, mysql, and Virtual Aliases


Hey all, I've got a working Virtual Postfix server running with mysql doing user authentication. I have a support email address set as support@hostname.com, which has 5 aliases associated; user1, user2, user3, user4, and user5. When an email is sent to support@hostname.com, all 5 users receive the email, just as planned. What I'm looking to do is when an email is sent to support@hostname.com to have it rotate through the members of the alias group. That way all members of the group get support emails evenly and not everybody all at once. Is this possible?

Many Thanks ahead of time!
 
Old 10-15-2010, 07:19 AM   #2
Germanchu
LQ Newbie
 
Registered: Nov 2009
Location: Buenos Aires, Argentina
Posts: 23

Rep: Reputation: 0
Hve almost the same setup, but using dovecot as pop3/imap and lda agent.

Maybe you can try modifying the query that obtains the alias destination when you query the database for support@.. It occurs to me that you might be able to implement some kind of "load-balance" between the destination addresses via SQL, but you would need to mantain account of the last destination address used.

Another solution would be using a shared IMAP folder and send the support emails there, that way each user does know which mails are read and which ones not, but this is slightly different than what you're asking for.

I hope it helps.

Best rgds!
 
Old 10-15-2010, 10:36 AM   #3
kipphudson
LQ Newbie
 
Registered: Feb 2008
Location: Pasco, WA
Posts: 2

Original Poster
Rep: Reputation: 0
In my mysql_virtual_alias_maps.cf I have the line that reads

query = SELECT username FROM supportemail WHERE support='%s' AND id = '1'

About the closest I've gotten is having the query choose id 1. The one thing that would make this work is either A: Have something that will edit my config file that will rotate between id's 1-5 every time a query is made, or B: Have something that will auto rotate the id numbers 1-5 in the mysql table every time a query is made.

Also, the IMAP idea would work too. I may just propose that idea instead.
 
Old 10-15-2010, 11:34 PM   #4
Germanchu
LQ Newbie
 
Registered: Nov 2009
Location: Buenos Aires, Argentina
Posts: 23

Rep: Reputation: 0
Maybe something like this (haven't trie so I don't know if it works as is... but the concept is complete):

// query that you put in postfix virtual_domains config file:
SELECT CASE '%s' WHEN 'support@domain.com' THEN getSupportAddress('%s') ELSE goto END FROM alias_table WHERE address = '%s' AND active = 1;

// This mysql function does the hard work for selecting the least recently used destination and updating the database's timestamp
CREATE FUNCTION getSupportAddress (INOUT VARCHAR address) RETURNS varchar
BEGIN
-- select the address that was used least recently
SET @tmp = SELECT goto FROM alias WHERE address = @address ORDER BY last_used LIMIT 1;
-- update that address' timestamp with the current time, to avoid selecting it next time
UPDATE alias SET last_used = NOW() WHERE address = @address;
-- return the alias destination
RETURN @tmp;
END

It has the downside that you have to add an extra column (timestamp) to the aliases table only to keep account of the support alias usage.

Let me know if this is of any help!

Best regards!
German
 
Old 10-15-2010, 11:36 PM   #5
Germanchu
LQ Newbie
 
Registered: Nov 2009
Location: Buenos Aires, Argentina
Posts: 23

Rep: Reputation: 0
Quote:
Originally Posted by Germanchu View Post
Maybe something like this (haven't trie so I don't know if it works as is... but the concept is complete):

// query that you put in postfix virtual_domains config file:
SELECT CASE '%s' WHEN 'support@domain.com' THEN getSupportAddress('%s') ELSE goto END FROM alias_table WHERE address = '%s' AND active = 1;

// This mysql function does the hard work for selecting the least recently used destination and updating the database's timestamp
CREATE FUNCTION getSupportAddress (INOUT VARCHAR address) RETURNS varchar
BEGIN
-- select the address that was used least recently
SET @tmp = SELECT goto FROM alias WHERE address = @address ORDER BY last_used LIMIT 1;
-- update that address' timestamp with the current time, to avoid selecting it next time
UPDATE alias SET last_used = NOW() WHERE address = @address;
-- return the alias destination
RETURN @tmp;
END

It has the downside that you have to add an extra column (timestamp) to the aliases table only to keep account of the support alias usage.

Let me know if this is of any help!

Best regards!
German
First corrections to the function:

CREATE FUNCTION getSupportAddress (address VARCHAR) RETURNS varchar
BEGIN
-- select the address that was used least recently
SET @tmp = SELECT goto FROM alias WHERE address = @address ORDER BY last_used LIMIT 1;
-- update that address' timestamp with the current time, to avoid selecting it next time
UPDATE alias SET last_used = NOW() WHERE address = @tmp;
-- return the alias destination
RETURN @tmp;
END

 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
how to create aliases and virtual table in postfix achilies Linux - Software 1 06-05-2010 12:42 PM
postfix & virtual aliases ddaas Linux - Server 1 12-06-2009 12:42 PM
Postfix/Dovecot not querying virtual aliases with smtp-auth coolster Linux - Software 0 05-26-2009 08:38 AM
Postfix Mysql Virtual Hosting Issues geek768 Linux - Server 1 02-27-2008 06:24 AM
Postfix: bouncing non-existing virtual aliases zerg4141 Linux - Enterprise 0 07-20-2006 04:43 PM

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

All times are GMT -5. The time now is 09:24 AM.

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