2013-10-16

‎Postfix 2: Email based queue & action selection:

← Older revision

Revision as of 19:00, October 16, 2013

(2 intermediate revisions by one user not shown)

Line 12:

Line 12:

 

postfix/local[28382]: 41646618D: to=<http://localhost/@example.net>, orig_to=<rt>, relay=local, delay=0, status=bounced (unknown user: "http://localhost/")

 

postfix/local[28382]: 41646618D: to=<http://localhost/@example.net>, orig_to=<rt>, relay=local, delay=0, status=bounced (unknown user: "http://localhost/")

 

postfix/qmgr[3332]: 41646618D: removed

 

postfix/qmgr[3332]: 41646618D: removed



 

 

 

 

The solution is to set up virtual aliases that direct virtual addresses to the local delivery agent:

 

The solution is to set up virtual aliases that direct virtual addresses to the local delivery agent:

Line 19:

Line 18:

 

 

 

virtual_alias_maps = pgsql:/etc/postfix/virtual

 

virtual_alias_maps = pgsql:/etc/postfix/virtual



 

 

 

 

Virtual data in SQL database following this idea:

 

Virtual data in SQL database following this idea:

Line 25:

Line 23:

 

rt@example.com goes to rt

 

rt@example.com goes to rt

 

rt-comment@example.com goes to rt-comment

 

rt-comment@example.com goes to rt-comment



 

 

 

 

/etc/aliases:

 

/etc/aliases:

Line 31:

Line 28:

 

rt: "|/opt/rt3/bin/rt-mailgate --queue general --action correspond --url http://localhost/"

 

rt: "|/opt/rt3/bin/rt-mailgate --queue general --action correspond --url http://localhost/"

 

rt-comment: "|/opt/rt3/bin/rt-mailgate --queue general --action comment --url http://localhost/"

 

rt-comment: "|/opt/rt3/bin/rt-mailgate --queue general --action comment --url http://localhost/"



 

 

 

 

PS:

 

PS:

 

 

 

Remeber to do a 'newaliases' command to make the new alias database.

 

Remeber to do a 'newaliases' command to make the new alias database.



 

 

 

 

This example assumes that in main.cf, $myorigin is listed under the mydestination parameter setting. If that is not the case, specify an explicit domain name on the right-hand side of the virtual alias table entries or else mail will go to the wrong domain.

 

This example assumes that in main.cf, $myorigin is listed under the mydestination parameter setting. If that is not the case, specify an explicit domain name on the right-hand side of the virtual alias table entries or else mail will go to the wrong domain.

Line 45:

Line 40:

 

 

 

<nowiki>* In case of a virtual alias domain, there would need to be one identity mapping from each mailing list address to itself.

 

<nowiki>* In case of a virtual alias domain, there would need to be one identity mapping from each mailing list address to itself.



* In case of a virtual mailbox domain, there would need to be a dummy mailbox for each mailing list address.

+

* In case of a virtual mailbox domain, there would need to be a dummy mailbox for each mailing list address.



+



</nowiki>

+

</nowiki>

 

 

 

Original explanation from www.postfix.org/VIRTUAL_README.html#mailing_lists

 

Original explanation from www.postfix.org/VIRTUAL_README.html#mailing_lists

Line 62:

Line 57:

 

 

 

<nowiki>#rt

 

<nowiki>#rt



rt unix - n n - - pipe

+

rt unix - n n - - pipe



flags=R user=vmail argv=/opt/rt3/bin/rt-mailgate --queue ${user} --action correspond --url http://example.com/

+

flags=R user=vmail argv=/opt/rt3/bin/rt-mailgate --queue ${user} --action correspond --url http://example.com/



+



</nowiki>

+

</nowiki>

 

 

 

Virtual data in database (virtual_alias_maps=mysql:/etc/postfix/virtual.cf) :

 

Virtual data in database (virtual_alias_maps=mysql:/etc/postfix/virtual.cf) :

Line 71:

Line 66:

 

rt@example.com goes to rt@localhost

 

rt@example.com goes to rt@localhost

 

rt-comment@example.com goes to rt-comment@localhost

 

rt-comment@example.com goes to rt-comment@localhost



 

 

 

 

Virtual Transport (transport_maps):

 

Virtual Transport (transport_maps):

Line 77:

Line 71:

 

example.com uses virtual, username=vmail

 

example.com uses virtual, username=vmail

 

localhost uses pipe, username=vmail

 

localhost uses pipe, username=vmail



 

 

 

 

In this setup the queue name must be the username (part left of @) for the email address.

 

In this setup the queue name must be the username (part left of @) for the email address.

Line 90:

Line 83:

 

 

 

flags=R user=vmail argv=/opt/rt3/bin/rt-mailgate --queue ${user} --action ${nexthop} --url http://example.com/

 

flags=R user=vmail argv=/opt/rt3/bin/rt-mailgate --queue ${user} --action ${nexthop} --url http://example.com/



 

 

 

 

The ${user} variable gets replaced with the username part of the email address. The ${nexthop} variable gets replaced by whatever is after 'rt:' below.

 

The ${user} variable gets replaced with the username part of the email address. The ${nexthop} variable gets replaced by whatever is after 'rt:' below.

Line 101:

Line 93:

 

 

 

-[mailto:aaron@darkpixel.com aaron@darkpixel.com]

 

-[mailto:aaron@darkpixel.com aaron@darkpixel.com]

 

+

 

+

== Postfix 2: Email based queue & action selection ==

 

+

I used a tweaked method from what Fahd has above. Using my method, you can send comments and correspondence based on the recipient email address. The pre-condition is that each queue must have a different correspondence address and comment address. I use a script rt-smart-mailgate which resolves the queue name and action and pipes the mail to rt-mailgate. This is for RT 3.8 with rt-mailgate at /usr/bin/rt-mailgate:

 

+

#!/usr/bin/perl -w

 

+

 

+

use warnings;

 

+

 

+

BEGIN {

 

+

use lib '/usr/share/request-tracker3.8/lib';

 

+

use RT;

 

+

RT::LoadConfig();

 

+

RT::Init();

 

+

}

 

+

 

+

use Getopt::Long;

 

+

 

+

my %opts;

 

+

GetOptions( \%opts, "qaddr=s", "url=s", "jar=s", "help", "debug", "extension=s", "timeout=i" );

 

+

 

+

sub pipe_mailgate {

 

+

my ( $queue, $action ) = @_;

 

+

 

+

$cmd_pipe = "|/usr/bin/rt-mailgate";

 

+

while (my ($arg, $val) = each(%opts)) {

 

+

$cmd_pipe .= sprintf(" --%s=%s", $arg, $val);

 

+

}

 

+

 

+

open($fh, "$cmd_pipe --queue $queue --action $action");

 

+

print $fh <STDIN>;

 

+

close($fh);

 

+

}

 

+

 

+

$qaddr = delete $opts{qaddr};

 

+

 

+

my $queues = RT::Queues->new($RT::SystemUser);

 

+

$queues->UnLimit();

 

+

 

+

while (my $queue = $queues->Next) {

 

+

my $qname = $queue->Name;

 

+

foreach my $action (qw/correspond comment/) {

 

+

my $method = ucfirst($action) . "Address";

 

+

my $mail_addr = $queue->$method || ${"RT::$method"};

 

+

if ($mail_addr eq $qaddr) {

 

+

pipe_mailgate($qname, $action);

 

+

exit;

 

+

}

 

+

}

 

+

}

 

+

 

+

pipe_mailgate("General", "correspond");

 

+

 

+

 

+

My virtual_alias_maps all aliased to rt@localhost:

 

+

rt@example.com rt@localhost

 

+

rt-comment@example.com rt@localhost

 

+

support@example.com rt@localhost

 

+

support-comment@example.com rt@localhost

 

+

...

 

+

My transport_maps:

 

+

rt@localhost rt

 

+

In master.cf, I have:

 

+

rt unix - n n - - pipe

 

+

flags=R user=virtual argv=/usr/bin/rt-smart-mailgate --url http://example.com/rt --qaddr ${original_recipient}

 

+

To get this to work, you'll need to allow the user virtual (or vmail) to read RT_SiteConfig.pm, since for security reasons, the file is not normally readable by non-root users.

 

+

 

+

- [http://terence.monteiro.in Terence Monteiro]

Show more