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 02-24-2014, 11:14 AM   #1
salantrax
LQ Newbie
 
Registered: Feb 2014
Posts: 7

Rep: Reputation: Disabled
Question Postfix: Advanced /sender/ address rewriting using external script.


Hello!

I have a working Postfix/Dovecot setup with virtual domains and users in a mySQL database.

Problem:

I need to do some rewriting of the sender addresses of outgoing mail according to this general rule/pseudocode:

IF
(user=MYVIRTUALUSER@mydomain.address) AND
(Subject.Field.Contains.The.String = "send.as.barbara")
THEN:
Swap all instances of "From: MYVIRTUALUSER@mydomain.address" to
"From: barbara@other.domain.address"

What this is meant to accomplish:

When I use a remote mail client, I can choose sender identity based on the content of the Subject: field.

If no special string is put into Subject:, then the mail is left unchanged (From: MYVIRTUALUSER@mydomain.address).

If a special string "send.as.x" is put into Subject:, then the filter script changes From: fields, so that Postfix relays the mail to predefined (authenticated) SMTP servers by use of sender_dependent_relayhost_maps.

This makes possible "server side identity management" for the case that I use a really stupid (!) mail client with no identity management of its own, and that can use only 1 SMTP server.

What I've tried so far:

Nothing!

I was thinking I could use 'procmail' to do this, but it seems that it can only act on /incoming/ mail, not outgoing.

The built-in Postfix address rewriting features don't seem to be flexible enough to do rewriting based on a regex in specific fields (or anywhere).

My question:

What can I use to rewrite Sender address according to the rule above? A shell script? How do I make Postfix filter outgoing mail through it?

EDIT:
This page http://www.debianadmin.com/how-to-ad...n-postfix.html looks close to what I want to do! Seems to use the "dfilt" pipe?

Last edited by salantrax; 02-26-2014 at 01:14 PM. Reason: Found a related tutorial. Including the link here!
 
Old 02-26-2014, 11:41 AM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,635

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
You can do one of two things:The new transport can be something like:
Code:
<some script name> unix - n n - 10 pipe flags=R user=vmail argv=/path/to/script -o SENDER=${sender} -m USER=${user} EXTENSION=${extension}
 
1 members found this post helpful.
Old 02-26-2014, 01:14 PM   #3
salantrax
LQ Newbie
 
Registered: Feb 2014
Posts: 7

Original Poster
Rep: Reputation: Disabled
Aha!

"After-queue content filters" looks simple enough and would probably allow some exotic manupilation.

(Hoping that performance won't suffer too much...)

Thank you!

Last edited by salantrax; 02-26-2014 at 01:14 PM. Reason: typo
 
Old 09-30-2014, 08:31 AM   #4
bilogic
LQ Newbie
 
Registered: Sep 2014
Posts: 3

Rep: Reputation: Disabled
Salantrax, did you managed to find a way to do this?
I kind of need to do the same as well.. thank you
 
Old 09-30-2014, 09:32 AM   #5
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,635

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by bilogic View Post
Salantrax, did you managed to find a way to do this? I kind of need to do the same as well.. thank you
The solution was given above, in post #2. Either enable after-queue processing, or a new transport script, as noted.
 
Old 09-30-2014, 09:50 AM   #6
bilogic
LQ Newbie
 
Registered: Sep 2014
Posts: 3

Rep: Reputation: Disabled
Hi TB0ne,

I did try the after queue filters, but it did not work out. Let me explain:

I have ssmtp installed so that sendmail sends everything out as abc@gmail.com
I'm not sure how my postfix works, but it is handling other domains correctly.

this is how my relayhost_map looks like

@example.com [example.com]:25
@hotmail.com [smtp.live.com]:25
@gmail.com [smtp.gmail.com]:587

when I followed the 30 line shell script on http://www.postfix.org/FILTER_README.html and send a test mail from abc@example.com, it was always received as abc@gmail.com, not abc@example.com

Basically, sendmail is behaving the way I want it to, however the script relies on sendmail to pass filtered content back to postfix. I have no idea how to overcome this. Any help is greatly appreciated.

Last edited by bilogic; 09-30-2014 at 10:04 AM. Reason: typo
 
Old 09-30-2014, 09:56 AM   #7
bilogic
LQ Newbie
 
Registered: Sep 2014
Posts: 3

Rep: Reputation: Disabled
As for the new transport, your previous example is too terse for me to understand. I did try googling, but gave up. Main trouble is not knowing how the script is supposed to handle inputs from and output returns to postfix.

As my mail server is handling live emails, I was hoping for a more walk-through example, rather than experimentation that may break something.

Any pointers will be greatly appreciated! (btw I'm conversant in php, that's what i'm hoping to write the script in) Thank you!

Last edited by bilogic; 09-30-2014 at 09:57 AM. Reason: typo
 
  


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
[SOLVED] Emails from postfix to external address display sender as 'user@mail.example.net' YellowApple Slackware 5 07-12-2013 03:25 AM
Postfix Address Rewriting Scenario shanky73 Linux - General 1 06-07-2013 01:50 AM
POSTFIX LDAP address rewriting kalidoss Linux - Server 0 06-07-2012 01:28 AM
Sender Name Rewriting in Postfix ojha_riddhish Linux - Server 2 01-09-2010 12:24 AM
Postfix: Rewriting sender email address from ldap lookups endfx Linux - Server 3 04-18-2008 03:53 PM

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

All times are GMT -5. The time now is 11:56 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