LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 04-10-2009, 03:20 PM   #1
officecase
Member
 
Registered: Jan 2007
Distribution: Centos, ArchLinux
Posts: 40

Rep: Reputation: 18
POSTFIX smtpd block by to: field


Hello all,
This is what I am trying to do...
I need to only allow email to be received that matches this pattern

<1[2-9]{10}@vm.myserver\.com>

I created a catch all for all mail. But now I want to reject any incoming mail that does not match that pattern hopefully in the SMTPD. I am hoping there is a way to do this. I am sure there is a better way to go about this. Any help would be appreciated.

here is my main.cf

Code:
#  Banner
smtpd_banner = $myhostname ESMTP $mail_name ($mail_version)

mail_owner = postfix
default_privs = nobody
myhostname = fun.myserver.com
mydomain = myserver.com
myorigin = $mydomain

queue_directory = /zxa/mail/drop
mail_spool_directory = /zxa/mail/spool
command_directory = /usr/sbin
daemon_directory = /usr/lib/postfix
data_directory = /var/lib/postfix

sendmail_path = /usr/sbin/sendmail
mailq_path = /usr/bin/mailq
setgid_group = postdrop


# RECEIVING MAIL
inet_interfaces = all
mydestination = $myhostname, $mydomain, localhost

##  SMTPD
smtpd_helo_required = yes

    
#  RELAY CONTROL
#  Examples 168.100.189.0/28, 127.0.0.0/8
#  Add IP to relay_allow_list to allow relaying
mynetworks = 127.0.0.1, /etc/postfix/relay_allow_list


#  Virtual alias catchall account and process email
mailbox_command = /usr/bin/procmail
virtual_alias_maps = hash:/etc/postfix/db/virtual_mailbox
here is my virtual_mailbox
Code:
postmaster@myserver.com            root
@myserver.com  root

Thanks in advance!!

Last edited by officecase; 04-10-2009 at 11:48 PM. Reason: fix code
 
Old 04-10-2009, 08:35 PM   #2
Berhanie
Senior Member
 
Registered: Dec 2003
Location: phnom penh
Distribution: Fedora
Posts: 1,625

Rep: Reputation: 165Reputation: 165
Just use a regexp table for virtual_alias_maps, e.g.
Code:
virtual_alias_maps = regexp:/etc/postfix/db/virtual_mailbox
Code:
/^postmaster@vm.axacore\.com$/    root
/^1[2-9]{10}@vm.myserver\.com$/    root

Last edited by Berhanie; 04-10-2009 at 08:37 PM.
 
Old 04-11-2009, 03:00 AM   #3
officecase
Member
 
Registered: Jan 2007
Distribution: Centos, ArchLinux
Posts: 40

Original Poster
Rep: Reputation: 18
Thanks

That was exactly what I was looking for!

I don't know if you can help me with another question.

I am trying to do TEXT SUBSTITUTION using header_checks. when an email comes in I want to add on additional chars. I have tested my regexp with postmap -q and it works great. But in my config when I receive an email it does not add the additional text

header_checks
Code:
if /^to:.*<[0-9]{7}@myserver\.com>/ 
/^to:(.*)<(.*)/   to:$(1)<1555$(2)
endif
in my config I have added

header_checks = regexp:/etc/postfix/header_checks


When the email hits the server the 1555 is not re-written in the email header.

Any clue?

Last edited by officecase; 04-11-2009 at 10:59 AM.
 
Old 04-11-2009, 10:10 AM   #4
Berhanie
Senior Member
 
Registered: Dec 2003
Location: phnom penh
Distribution: Fedora
Posts: 1,625

Rep: Reputation: 165Reputation: 165
You're welcome. For your next question, please fix your "code" stanza and
explain in words what you're trying to do.
 
Old 04-11-2009, 11:11 AM   #5
officecase
Member
 
Registered: Jan 2007
Distribution: Centos, ArchLinux
Posts: 40

Original Poster
Rep: Reputation: 18
Oops

Okay, fixed. If someone is sending an email to

3235631@myserver.com

When the email is received I want to add on the area code to the email address before it drops the email into the users inbox. The end result should look like...

18883235631@myserver.com

From what I thought, I could perform this with the
header_checks = regexp:/etc/postfix/header_checks

After I send a test email. I look in the eml header on the received email and see no change.
 
Old 04-11-2009, 12:29 PM   #6
Berhanie
Senior Member
 
Registered: Dec 2003
Location: phnom penh
Distribution: Fedora
Posts: 1,625

Rep: Reputation: 165Reputation: 165
It would be easier to rewrite the envelope, as you did above using virtual_alias_maps, rather than the headers, since the "To:" header can contain several recipients, each one being in one of several forms, i.e.. "The Name" followed by <user@address.com>, or just a simple user@address.com (no name, no angle brackets); so you'll have to handle those possibilities (see RFC 2833). But, you can prepend the area code to a simple address of the form "[0-9]{7}@myserver.com" using something like
Code:
header_checks = regexp:/etc/postfix/header_checks
and
Code:
/^To: ([0-9]{7}@myserver\.com)$/ REPLACE To: 1555${1}
 
Old 04-12-2009, 12:48 AM   #7
officecase
Member
 
Registered: Jan 2007
Distribution: Centos, ArchLinux
Posts: 40

Original Poster
Rep: Reputation: 18
Once again thank you for all your help. Your last reply made the light click on when reading the man page for header_checks.

Do you have any links for a good read on postfix beside the postfix site?
 
Old 04-12-2009, 11:21 AM   #8
Berhanie
Senior Member
 
Registered: Dec 2003
Location: phnom penh
Distribution: Fedora
Posts: 1,625

Rep: Reputation: 165Reputation: 165
Yeah, people have used the word "scattered" to describe the postfix documentation. There's no substitute for the material on the site, but there are supplements. This page links to some of them. The two people mentioned near the top have each written a book, this and this. From what I recall (maybe someone will correct me), they both cover postfix around version 2.0 or 2.1, so they're a little out of date, but still good. I like the first for its brevity. Don't let the old publication date of the first put you off: it was published in late 2003, while the second in early 2005.

Last edited by Berhanie; 04-12-2009 at 11:22 AM.
 
Old 04-13-2009, 02:47 AM   #9
officecase
Member
 
Registered: Jan 2007
Distribution: Centos, ArchLinux
Posts: 40

Original Poster
Rep: Reputation: 18
One more

Okay I have one more.

I want to do this. Not sure if it is possible. I am sending an email to u20090412122345@someplace.com

Using the header_checks I am checking for this
/^to:.*<[u][0-9]{14}@someplace\.com$>/

Then I want to change the from format.
Original would be

from: Joe dirt <jdirt@whoknows.com>

rewrite to

from: u20090412122345 <jdrit@whoknows.com>

I have tried so far...
Code:
if /^to:.*<([u][0-9]{14})@someplace\.com$>/
/^from:(.*)<(.*)>$/    REPLACE from:${2}"${1}" <${3}>
endif
I get an error that 3 is invalid. is it passable to grab the var from if line?
 
Old 04-13-2009, 06:19 AM   #10
Berhanie
Senior Member
 
Registered: Dec 2003
Location: phnom penh
Distribution: Fedora
Posts: 1,625

Rep: Reputation: 165Reputation: 165
header_checks only works with one header at a time, and doesn't maintain state between headers. Each header -- one at a time -- is matched against pattern1 and pattern2 in the construct below:
Code:
if /pattern1/ ...
/pattern2/ ...
endif
So, what you're trying to do is not possible. It may be possible using a milter.
 
  


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
postfix/smtpd lost connection after CONNECT [GOD]Anck Linux - Security 1 12-18-2011 02:10 PM
postfix / smtpd is rejecting all incoming emails alitrix Linux - Server 2 06-06-2008 04:10 PM
Postfix error: /usr/lib/postfix/smtpd pid 7529 exit status 1 Chiragrs Linux - Networking 7 05-16-2008 12:42 AM
Problem with Postfix (process smtpd exit status 1) breiko Linux - Server 18 03-26-2008 02:02 PM
Smtp vs. Smtpd on Postfix BeerBust Linux - Software 1 10-10-2003 11:07 AM

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

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