LinuxQuestions.org
Visit Jeremy's Blog.
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 05-05-2018, 04:23 AM   #1
synner
LQ Newbie
 
Registered: May 2018
Location: Bulgaria
Posts: 2

Rep: Reputation: Disabled
Question Configure Postfix SMTP Relay with sender_canonical_maps


Hello, fellas

I have a couple of servers in a private LAN 10.0.0.0/24.
I've set up one of the servers with Postfix in a effort to relay internal mails to an external SMTP server (of my ISP).

Every server in my LAN runs a variety of test apps (in a lab-like environment) and they send out various mail notifications and reports. Every app's settings for mail sender are (usually) in the form of <app>@lab.local but it can be anything, really.

My question boils down to how to configure Postfix to perform the following rewrite in the SMTP envelope and not header.

<myapp>@<randomlocal.domain> ----> <myapp>.<randomlocal.domain>@mylegitinternetdomain.com
And then relay it to the external ISP SMTP.

Recipients' SMTP envelope and header should not get modified.

I got so far:
/etc/postfix/main.cf
Code:
smtpd_banner = $myhostname ESMTP $mail_name ($mail_version)
smtpd_helo_required = yes

inet_interfaces = 127.0.0.1, 10.0.0.1
inet_protocols = ipv4

relayhost = [smtp.myisp.com]

myhostname = mail.lab.local
mydomain = lab.local

myorigin = $mydomain
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain

mynetworks_style = subnet
mynetworks = 127.0.0.0/8, 10.0.0.0/24

append_at_myorigin = no
append_dot_mydomain = no

local_header_rewrite_clients = permit_inet_interfaces, permit_mynetworks, reject
remote_header_rewrite_domain = domain.invalid

masquerade_domains = $mydomain

sender_canonical_classes = envelope_sender
sender_canonical_maps = regexp:/etc/postfix/canonical_maps_sender
/etc/postfix/canonical_maps_sender
Code:
if !/@mylegitinternetdomain\.com/i
/^.*?([^\s<]+?)@([^\s>]+?)>?\s*$/i      ${1}.${2}@mylegitinternetdomain.com
endif
My regex seems to be wrong as in my Inbox from the ISP SMTP I get mails from "lab.local"@mylegitinternetdomain.com

Help!!!
What am I missing?

Thank you in advance!
 
Old 05-28-2018, 03:36 AM   #2
synner
LQ Newbie
 
Registered: May 2018
Location: Bulgaria
Posts: 2

Original Poster
Rep: Reputation: Disabled
Lightbulb

Postfix's Regex engine seems rather pretentious. Seems it does not fancy complex regex.
After numerous tests, went back to basics, gradually introduces complications, finally managed achieve my goal with:
Code:
root@mailsrv:/etc/postfix # cat canonical_maps_sender
if !/.+?@myinetdomain\.com/i
/(.+?)@(.+)/i           ${1}\.${2}@myinetdomain\.com
endif
Problem solved, I guess...
 
  


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 Multiple SMTP Relay contertulio Linux - Server 0 02-06-2013 10:44 AM
LXer: How to configure postfix as smtp relay for Gmail on Archlinux LXer Syndicated Linux News 0 01-04-2013 06:10 AM
Postfix SMTP relay dvishloff Linux - Server 6 12-29-2011 03:14 PM
postfix smtp relay ormey2000 Linux - Server 2 01-19-2010 07:24 AM
Postfix as SMTP relay to exchange help GGlinux Linux - Server 6 07-29-2009 09:10 PM

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

All times are GMT -5. The time now is 03:21 PM.

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