PostFixSQLAliasProblem: Difference between revisions
(Email based queue, action selection) |
m (7 revisions imported) |
||
(4 intermediate revisions by 2 users not shown) | |||
Line 40: | 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. | |||
</nowiki> | |||
Original explanation from www.postfix.org/VIRTUAL_README.html#mailing_lists | Original explanation from www.postfix.org/VIRTUAL_README.html#mailing_lists | ||
Line 57: | Line 57: | ||
<nowiki>#rt | <nowiki>#rt | ||
rt unix - n n - - pipe | |||
flags=R user=vmail argv=/opt/rt3/bin/rt-mailgate --queue ${user} --action correspond --url http://example.com/ | |||
</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 80: | Line 80: | ||
I used a slight tweaked method than what Fahd has above. The benefit to my method is that you can send comments instead of just sending correspondence. Also, several other examples throughout the wiki use VERP (the plus sign) in the email address to denote the action which is potentially could be a security issue (Maybe someone could address general+[mailto:take@example.com take@example.com] or general+[mailto:merge@example.com.. merge@example.com..].?). I have a virtual-only mail server. No local accounts. I believe my method works much better. | I used a slight tweaked method than what Fahd has above. The benefit to my method is that you can send comments instead of just sending correspondence. Also, several other examples throughout the wiki use VERP (the plus sign) in the email address to denote the action which is potentially could be a security issue (Maybe someone could address general+[mailto:take@example.com take@example.com] or general+[mailto:merge@example.com.. merge@example.com..].?). I have a virtual-only mail server. No local accounts. I believe my method works much better. | ||
In /etc/master.cf add the following lines: | In /etc/master.cf add the following lines: | ||
flags=R user=vmail argv=/opt/rt3/bin/rt-mailgate --queue ${user} --action ${nexthop} --url http://example.com/ | <span style="font-family:Helvetica,Arial,sans-serif;line-height:22px;">rt unix - n n - - pipe | ||
</span> 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 88: | Line 89: | ||
In my case, I use /etc/postfix/virtual_transports instead of SQL, but the mappings are the same. | In my case, I use /etc/postfix/virtual_transports instead of SQL, but the mappings are the same. | ||
general@example.com rt:correspond | |||
general-comment@example.com rt:comment | |||
testqueue@example.com rt:correspond | |||
testqueue-comment@example.com rt:comment | |||
...etc... | |||
Remember: Virtual Transports in Postfix don't have to apply to an entire domain, they can apply to specific e-mail addresses as well. This works out well if you want to share your 'example.com' domain with RT in addition to using it as your companies primary domain. | Remember: Virtual Transports in Postfix don't have to apply to an entire domain, they can apply to specific e-mail addresses as well. This works out well if you want to share your 'example.com' domain with RT in addition to using it as your companies primary domain. | ||
-[mailto:aaron@ | -[mailto:aaron@heyaaron.com aaron@heyaaron.com] | ||
== Postfix 2: Email based queue & action selection == | == Postfix 2: Email based queue & action selection == | ||
Line 146: | Line 151: | ||
My virtual_alias_maps all aliased to rt@localhost: | My virtual_alias_maps all aliased to rt@localhost: | ||
rt@example.com rt@localhost | rt@example.com rt@localhost | ||
rt-comment@example.com rt@localhost | rt-comment@example.com rt@localhost | ||
support@example.com rt@localhost | support@example.com rt@localhost | ||
support-comment@example.com rt@localhost | support-comment@example.com rt@localhost | ||
... | ... | ||
My transport_maps: | My transport_maps: | ||
rt@localhost rt | rt@localhost rt | ||
In master.cf, I have: | In master.cf, I have: | ||
rt unix - n n - - pipe | rt unix - n n - - pipe | ||
flags=R user=virtual argv=/usr/bin/rt-smart-mailgate --url http://example.com/rt --qaddr ${original_recipient} | 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. | 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] |
Latest revision as of 15:20, 6 April 2016
In my case ive got this error (Example):
postfix/pickup[28293]: 41646618D: uid=0 from=<root> postfix/cleanup[28375]: 41646618D: message-id=<20050104225650.41646618D@example.net> postfix/qmgr[3332]: 41646618D: from=<root@example.net>, size=307, nrcpt=7 (queue active) postfix/qmgr[3332]: 41646618D: to=<--action@example.net>, orig_to=<rt>, relay=none, delay=0, status=bounced (invalid recipient syntax: "--action@example.net") postfix/qmgr[3332]: 41646618D: to=<--queue@example.net>, orig_to=<rt>, relay=none, delay=0, status=bounced (invalid recipient syntax: "--queue@example.net") postfix/qmgr[3332]: 41646618D: to=<--url@example.net>, orig_to=<rt>, relay=none, delay=0, status=bounced (invalid recipient syntax: "--url@example.net") postfix/local[28380]: 41646618D: to=<correspond@example.net>, orig_to=<rt>, relay=local, delay=0, status=bounced (unknown user: "correspond") postfix/local[28381]: 41646618D: to=<general@example.net>, orig_to=<rt>, relay=local, delay=0, status=bounced (unknown user: "general") postfix/local[28381]: 41646618D: to=<|/opt/rt3/bin/rt-mailgate@example.net>, orig_to=<rt>, relay=local, delay=0, status=bounced (unknown user: "|/opt/rt3/bin/rt-mailgate") 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
The solution is to set up virtual aliases that direct virtual addresses to the local delivery agent:
/etc/postfix/main.cf:
virtual_alias_maps = pgsql:/etc/postfix/virtual
Virtual data in SQL database following this idea:
rt@example.com goes to rt rt-comment@example.com goes to rt-comment
/etc/aliases:
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/"
PS:
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.
More information about the Postfix local delivery agent can be found in the local(8) manual page.
Why does this example use a clumsy virtual alias instead of a more elegant transport mapping? The reason is that mail for the virtual mailing list would be rejected with "User unknown". In order to make the transport mapping work one would still need a bunch of virtual alias or virtual mailbox table entries.
* 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.
Original explanation from www.postfix.org/VIRTUAL_README.html#mailing_lists
(posting above by Anonymous Gnome)
Postfix 2
I had to install RT in a setup where the only configured mail transport was virtual. I could not get the standard entry in /etc/aliases to work as detailed above.
Setup rt-mailgate using pipe in /etc/postfix/master.cf
#rt rt unix - n n - - pipe flags=R user=vmail argv=/opt/rt3/bin/rt-mailgate --queue ${user} --action correspond --url http://example.com/
Virtual data in database (virtual_alias_maps=mysql:/etc/postfix/virtual.cf) :
rt@example.com goes to rt@localhost rt-comment@example.com goes to rt-comment@localhost
Virtual Transport (transport_maps):
example.com uses virtual, username=vmail localhost uses pipe, username=vmail
In this setup the queue name must be the username (part left of @) for the email address.
-Fahd S.
Postfix 2 Tweaked
I used a slight tweaked method than what Fahd has above. The benefit to my method is that you can send comments instead of just sending correspondence. Also, several other examples throughout the wiki use VERP (the plus sign) in the email address to denote the action which is potentially could be a security issue (Maybe someone could address general+take@example.com or general+merge@example.com...?). I have a virtual-only mail server. No local accounts. I believe my method works much better.
In /etc/master.cf add the following lines:
rt unix - n n - - pipe 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.
In my case, I use /etc/postfix/virtual_transports instead of SQL, but the mappings are the same.
general@example.com rt:correspond general-comment@example.com rt:comment testqueue@example.com rt:correspond testqueue-comment@example.com rt:comment ...etc...
Remember: Virtual Transports in Postfix don't have to apply to an entire domain, they can apply to specific e-mail addresses as well. This works out well if you want to share your 'example.com' domain with RT in addition to using it as your companies primary domain.
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.