LinuxQuestions.org
Visit the LQ Articles and Editorials section
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 12-27-2010, 05:24 PM   #1
williebens
Member
 
Registered: Jan 2008
Posts: 88

Rep: Reputation: 16
Rewrite sender address in postfix


Hello Forum:

I need to have a postfix server to rewrite the sender's address.
For example, if the sender is: box@thisdomain.com, then the recipient would receive all emails from box@thisdomain.com as box@thatdomain.com.

I tried using the generic file and created a table out of it, but this did not work:

postmap /etc/postfix/generic

-rw-r--r-- 1 root root 9977 Dec 27 15:24 generic
-rw-r--r-- 1 root root 12288 Dec 27 15:25 generic.db

I added this line to the generic text file:
box@thisdomain.com box@thatdomain.com

I am running two boxes with postfix 2.3.3. and 2.1.1 respectively. Both need this configuration.


I also added this line:

smtp_generic_maps = hash:/etc/postfix/generic

on the main.cf file. However, this did not work.
The one running postfix 2.3.3 is on Centos 5.5, the other one is on SuSe Enterprise 9.

Can anyone out there help me how to configure postfix to do this?

Thanks.
--Willie

Last edited by williebens; 12-27-2010 at 05:25 PM.
 
Old 12-28-2010, 05:04 AM   #2
Reuti
Senior Member
 
Registered: Dec 2004
Location: Marburg, Germany
Distribution: openSUSE 11.4
Posts: 1,319

Rep: Reputation: 252Reputation: 252Reputation: 252
Do you want this for all email? You can rewrite it in sender_canonical and change it to regexp:
Code:
/^(.*@)thisdomain.com$/     ${1}thatdomain.com
and in main.cf
Code:
sender_canonical_maps = regexp:/etc/postfix/sender_canonical
As it's a regexp, there is no postmap necessary.

The generic table will handle only mail going to another machine AFAICS.
 
Old 12-28-2010, 10:04 AM   #3
williebens
Member
 
Registered: Jan 2008
Posts: 88

Original Poster
Rep: Reputation: 16
Hello Reuti:

Thanks for your reply. I tried your suggestion, but, unfortunately, it did not work.

Do you have any other idea?

Thanks.
--Willie
 
Old 12-28-2010, 10:25 AM   #4
Reuti
Senior Member
 
Registered: Dec 2004
Location: Marburg, Germany
Distribution: openSUSE 11.4
Posts: 1,319

Rep: Reputation: 252Reputation: 252Reputation: 252
You restarted postfix? I use this to rewrite the sender in the emails of a cluster, where the nodes have no valid DNS entry as they are in a private subnet. So it's known to work. Do you have any entries in /etc/postfix/transport, which might bypass the local filtering? There maybe hints in /var/log/mail or alike too.

The sender in the email is just unchanged?

What I notice though, is that I'm running 2.5.5 and 2.7.1. Do you have any chance to upgrade?
 
Old 12-28-2010, 10:57 AM   #5
williebens
Member
 
Registered: Jan 2008
Posts: 88

Original Poster
Rep: Reputation: 16
Hello Reuti:

I restarted postfix. I don't have any entry in the transport file.

This is my the /var/log/maillog shows:

Dec 28 11:44:03 boxname postfix/smtpd[5159]: disconnect from localhost.localdomain[127.0.0.1]
Dec 28 11:44:03 boxname postfix/smtp[5163]: 85176450036: to=<username@thatdomain.com>, relay=mailhost.thatdomain.com[10.200.1.155]:25, delay=0.33, delays=0.08/0.05/0.11/0.1, dsn=2.0.0, status=sent (250 Ok: queued as 7CD417C01B)
Dec 28 11:44:03 boxname postfix/qmgr[4982]: 85176450036: removed

Where:
boxname is the hostname of the box running postfix.
thatdomain is the domain this box belongs to.
username is the name of the sender.

Also, I would like to ask you what is the meaning of the ${1} part in the ${1}thatdomain.com regexp?

Thanks.
--Willie
 
Old 12-28-2010, 11:12 AM   #6
Reuti
Senior Member
 
Registered: Dec 2004
Location: Marburg, Germany
Distribution: openSUSE 11.4
Posts: 1,319

Rep: Reputation: 252Reputation: 252Reputation: 252
The ${1} will be replaced by the first found substring in the original sender address which matches (.*@), hence user and the @ character. This will stay untouched this way and the original domain is simply replaced with the one specified. You could also try:

Code:
/^(.*@).*$/     ${1}thatdomain.com
which won't check the original domain but replaces unconditionally anything.

You have no from= entry in the messages file?
 
Old 12-28-2010, 12:02 PM   #7
williebens
Member
 
Registered: Jan 2008
Posts: 88

Original Poster
Rep: Reputation: 16
This is what I have in my mail log:

Dec 28 12:54:12 box1 postfix/pickup[15082]: C11FF8F6D4: uid=0 from=<root>
Dec 28 12:54:12 box1 postfix/cleanup[20623]: C11FF8F6D4: message-id=<4D1A2444.mailFWS1ZWYKF@box1.thisdomain.com>
Dec 28 12:54:12 box1 postfix/qmgr[4846]: C11FF8F6D4: from=<root@box1.thisdomain.com>, size=457, nrcpt=1 (queue ac tive)
Dec 28 12:54:12 box1 postfix/smtp[20624]: C11FF8F6D4: to=<myname@thatdomain.com>, relay=box2mail.thisdomain.com[10.10.2.75], delay=0, status=sent (250 2.0.0 Ok: queued as 1E29E5806B)
Dec 28 12:54:12 box1 postfix/qmgr[4846]: C11FF8F6D4: removed


box1 one sends an email to myself@thatdomain.com. However, before I get the email, this email passes through box2mail that is a relay server.

I am using this regexp:
/^(.*@)thisdomain.com$/ ${1}thatdomain.com

Do you seen anything strange in the log file?

Thanks.
--Willie
 
Old 12-28-2010, 12:11 PM   #8
williebens
Member
 
Registered: Jan 2008
Posts: 88

Original Poster
Rep: Reputation: 16
Also, this is the main.cf file of the relay postfix server:

setgid_group = maildrop
manpage_directory = /usr/share/man
sample_directory = /usr/share/doc/packages/postfix/samples
readme_directory = /usr/share/doc/postfix-2.3.3/README_FILES

mail_spool_directory = /var/mail
bounce_queue_lifetime = 3d
canonical_maps = hash:/etc/postfix/canonical
virtual_maps = hash:/etc/postfix/virtual

relocated_maps = hash:/etc/postfix/relocated
transport_maps = hash:/etc/postfix/transport
sender_canonical_maps = regexp:/etc/postfix/sender_canonical
masquerade_exceptions = root

masquerade_classes = envelope_sender, header_sender, header_recipient
myhostname = box2mail.thisdomain.com
program_directory = /usr/lib/postfix
inet_interfaces = all

masquerade_domains = thisdomain.com
mydestination = $myhostname, localhost.$mydomain
defer_transports =
disable_dns_lookups = no

relayhost =
content_filter =
mailbox_command =
mailbox_transport =

smtpd_sender_restrictions = hash:/etc/postfix/access
smtpd_client_restrictions =
smtpd_helo_required = no
smtpd_helo_restrictions =

strict_rfc821_envelopes = no
mynetworks = 10.12.0.0/20, 127.0.0.1
smtpd_recipient_restrictions = permit_mynetworks,reject_unauth_destination
smtp_sasl_auth_enable = no

smtpd_sasl_auth_enable = no
smtpd_use_tls = no
smtp_use_tls = no
alias_maps = hash:/etc/aliases

mailbox_size_limit = 0
message_size_limit = 51200000
 
Old 12-28-2010, 12:44 PM   #9
williebens
Member
 
Registered: Jan 2008
Posts: 88

Original Poster
Rep: Reputation: 16
This is the main.cf file of the box I am sending the email from (box1) going through box2mail (relay box) and then to my myself@thatdomain. Where myself@thatdomain is my email address. When I receive the an email from box1, I should see it as box

readme_directory = /usr/share/doc/packages/postfix/README_FILES
mail_spool_directory = /var/mail
canonical_maps = hash:/etc/postfix/canonical
virtual_maps = hash:/etc/postfix/virtual

relocated_maps = hash:/etc/postfix/relocated
transport_maps = hash:/etc/postfix/transport
sender_canonical_maps = hash:/etc/postfix/sender_canonical
masquerade_exceptions = root

masquerade_classes = envelope_sender, header_sender, header_recipient
myhostname = box1.thisdomain.com
program_directory = /usr/lib/postfix
inet_interfaces = 127.0.0.1 ::1

masquerade_domains = thisdomain.com
mydestination = $myhostname, localhost.$mydomain
defer_transports =
disable_dns_lookups = no

relayhost = [box2mail.thisdomain.com]
content_filter =
mailbox_command =
mailbox_transport =
smtpd_sender_restrictions = hash:/etc/postfix/access
smtpd_client_restrictions =
smtpd_helo_required = no
smtpd_helo_restrictions =
strict_rfc821_envelopes = no
smtpd_recipient_restrictions = permit_mynetworks,reject_unauth_destination
smtp_sasl_auth_enable = no
smtpd_sasl_auth_enable = no
smtpd_use_tls = no
smtp_use_tls = no
alias_maps = hash:/etc/aliases
mailbox_size_limit = 0
message_size_limit = 10240000
 
Old 12-28-2010, 12:45 PM   #10
williebens
Member
 
Registered: Jan 2008
Posts: 88

Original Poster
Rep: Reputation: 16
Well, things have changed.

This is what I need to do really.

I need to tell postfix to forward these two addresses:

dbsupport@thisdomain.com
and
helpdesk@thisdomain.com

to

admins@thatdomain.com

Since now I am under pressure of time, is it possible for someone go guide me on how to do that?

Thanks.
--Wilie
 
Old 12-28-2010, 12:47 PM   #11
Reuti
Senior Member
 
Registered: Dec 2004
Location: Marburg, Germany
Distribution: openSUSE 11.4
Posts: 1,319

Rep: Reputation: 252Reputation: 252Reputation: 252
Quote:
Originally Posted by williebens View Post
Dec 28 12:54:12 box1 postfix/qmgr[4846]: C11FF8F6D4: from=<root@box1.thisdomain.com>,
Aha, there is a hostname included after the @. So the regexp must match the above, which is slightly different:

Code:
/^(.*@box1[.])thisdomain[.]com$/ ${1}thatdomain.com
or

Code:
/^(.*@)box1[.]thisdomain[.]com$/ ${1}box1.thatdomain.com
or

Code:
/^(.*)thisdomain[.]com$/ ${1}thatdomain.com
To test it without restarting postfix all the time:

Code:
postmap -q "fubar@box1.thisdomain.com" regexp:/etc/postfix/sender_canonical
Example:

Code:
$ postmap -q "fubar@box1.thisdomain.com" regexp:tester
fubar@box1.thatdomain.com
To make it active after your tests you have to reload postfix though.
 
Old 12-28-2010, 12:57 PM   #12
Reuti
Senior Member
 
Registered: Dec 2004
Location: Marburg, Germany
Distribution: openSUSE 11.4
Posts: 1,319

Rep: Reputation: 252Reputation: 252Reputation: 252
You will need a line in recipient_canonical. It's similar to sender_canonical.

Code:
/^((dbsupport|helpdesk).*)thisdomain[.]com$/ admins@thatdomain.com
and again an entry in main.cf referencing this regexp.

Code:
$ postmap -q "helpdesk@box1.thisdomain.com" regexp:tester
admins@thatdomain.com
And you have to change in main.cf:

Code:
sender_canonical_maps = regexp:/etc/postfix/sender_canonical
recipient_canonical_maps = regexp:/etc/postfix/recipient_canonical
It's no longer a hash.
 
Old 12-28-2010, 01:15 PM   #13
williebens
Member
 
Registered: Jan 2008
Posts: 88

Original Poster
Rep: Reputation: 16
Hello Reuti:

My boss is telling to do it as a transport. I am afraid that if I keep using sender_canonical and recipient_canonical, he might not be comfortable with it. Is there a way to achieve this:

I need to tell postfix to forward these two addresses:

dbsupport@thisdomain.com
and
helpdesk@thisdomain.com

to

admins@thatdomain.com

using transport?

I really appreciate your help because I am really under pressure here.

Thanks.
--Willie
 
Old 12-28-2010, 01:39 PM   #14
williebens
Member
 
Registered: Jan 2008
Posts: 88

Original Poster
Rep: Reputation: 16
This is the header of an email I sent from box1 to myself:

Received: from thatdomain.com (10.200.1.146) by atl-mes1.office.thatdomain.com
(10.12.1.36) with Microsoft SMTP Server (TLS) id 8.3.83.0; Tue, 28 Dec 2010
13:27:35 -0500
Received: from mailfilter-02 (mailfilter-02 [127.0.0.1]) by pps.atlredir
(8.14.1/8.14.1) with SMTP id oBSIRZ1Z004590 for <myself@thatdomain.com>;
Tue, 28 Dec 2010 13:27:35 -0500
Received: from box2mail.thisdomain.com (box2mail.thisdomain.com
[12.129.110.75] (may be forged)) by mailfilter-02 with ESMTP id
oBSIRKiC004490 for <myself@thatdomain.com>; Tue, 28 Dec 2010 13:27:35
-0500
Received: by box2mail.thisdomain.com (Postfix, from userid 1229) id
EB49858073; Tue, 28 Dec 2010 13:27:19 -0500 (EST)
To: <myself@thatdomain.com>
Subject: box2mail email
Message-ID: <20101228182719.EB49858073@box2mail.thisdomain.com>

Date: Tue, 28 Dec 2010 13:27:19 -0500
From: My Self <myself@thisdomain.com>
X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:5.2.15,1.0.148,0.0.0000
definitions=2010-12-28_09:2010-12-28,2010-12-28,1970-01-01 signatures=0
X-Proofpoint-Spam-Details: rule=notspam policy=default score=18 spamscore=18 ipscore=0 suspectscore=3
phishscore=0 bulkscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx
engine=6.0.2-1010190000 definitions=main-1012280082
MIME-Version: 1.0
Content-Type: text/plain
Return-Path: myself@thisdomain.com

I do not understand much what it means though.

Thanks.
--Willie
 
Old 12-28-2010, 01:57 PM   #15
Reuti
Senior Member
 
Registered: Dec 2004
Location: Marburg, Germany
Distribution: openSUSE 11.4
Posts: 1,319

Rep: Reputation: 252Reputation: 252Reputation: 252
Quote:
Originally Posted by williebens View Post
Using transport?
--Willie
No. With sender_canonical and recipient_canonical you can change the label on a bus going from: and to: With transport you change the street the bus has to take, depending on its destination.

Last edited by Reuti; 12-28-2010 at 02:11 PM.
 
  


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
Postfix: Rewriting sender email address from ldap lookups endfx Linux - Server 3 04-18-2008 03:53 PM
Postfix: Is it possible to rewrite sender address only for selective recipient? Akhran Linux - Software 3 08-15-2006 10:48 AM
postfix: forcing rewrite of 'To' address when sending imraven Linux - Software 4 06-15-2006 10:07 AM
Postfix - Sender address includes localhost buskmann Linux - Software 1 05-04-2005 07:56 AM
Postfix: Sender address rejected when matching $mydestination [GOD]Anck Linux - Software 1 02-16-2005 05:42 AM


All times are GMT -5. The time now is 04:14 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration