LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices



Reply
 
Search this Thread
Old 02-04-2006, 11:24 AM   #1
dlublink
Member
 
Registered: Oct 2004
Location: Canada
Distribution: Ubuntu
Posts: 329

Rep: Reputation: 30
Custom script for particular domain: User not found in local recepient table.


Hey All!

My friend has setup a server running imapuw and postfix. He has a single account hosted on this server, he offered to let me use his server to run a custom script.

What I want is the following:

Any mail sent to any username at the domain I specify is delivered via a custom bash script. I need to make the changes without interrupting his mail service.

What I tried was the following:

in the aliases table I put:
mydomain.net: "|/home/david/script.php"

I used postalias to compile it to aliases.db

I added mydomain.net to mydestination line in the main.cf of postfix.

It looks like it is checking the /etc/passwd file for the user, but I don't want it to do that for this particular domain. Instead I want it to use the aformentioned script. Ideally I would like my script to have a way to accept or reject emails. Maybe if I output something to stderr with my script it will do the trick?

The error I get is this:
###### Extract of /var/log/mail.log ######
Feb 4 11:14:34 linux_hostname postfix/smtpd[6282]: NOQUEUE: reject: RCPT from server.dnsname.tld[127.0.0.1]: 550 <i_am_so_cool@mydomain.net>: Recipient address rejected: User unknown in local recipient table; from=<myaddress@somehost.net> to=<i_am_so_cool@mydomain.net> proto=SMTP helo=<mydomain.net>
#########

If I use a name that exists in passwd with my domain
###
Feb 4 11:26:02 dunedin postfix/local[6305]: 786424809D: to=<david@mydomain.net>, relay=local, delay=21, status=sent (delivered to command: procmail -a "$EXTENSION")
####

I must have put my command in the wrong file or something...

Thanks,

David

Last edited by dlublink; 02-04-2006 at 11:27 AM.
 
Old 02-04-2006, 11:47 AM   #2
dlublink
Member
 
Registered: Oct 2004
Location: Canada
Distribution: Ubuntu
Posts: 329

Original Poster
Rep: Reputation: 30
Hey

I got it working. Here is what I did:

in the aliases file I added:

sms: "|/home/david/script.php"

I hashed it using postalias aliases

I added the domain to mydestinations.

I added the line:
virtual_alias_maps = hash:/etc/postfix/virtual

in virtual I put

@mydomain.net sms

I hashed it using

postmap hash:virtual
(this create virtual.db)

I typed:

postfix reload

Now all emails for mydomain.net are redirected to /home/david/script.php as if called with a pipe.

My script reads from standard in and drops it into my database. The only thing of note is that the headers of the email contained the following:

X-Original-To: darwin@mydomain.net
Delivered-To: sms@myhost.ca

darwin@mydomain.net is the address I gave after rcpt to: in SMTP(using telnet) and myhost.ca is the name specified in main.cf and sms is the virtual name I setup above.

David
 
Old 02-04-2006, 11:51 AM   #3
dlublink
Member
 
Registered: Oct 2004
Location: Canada
Distribution: Ubuntu
Posts: 329

Original Poster
Rep: Reputation: 30
Only thing I did not figure out how to do is return an error to postfix to reject the message.

I tried writing to the standard error but it didn't work. So if anyone knows how my script can tell postfix that the message was not delivered, that would help me a lot.

I found an article (after I got it to work) at http://www.evolt.org/article/Incomin..._PHP/18/27914/ if anyone is interested.

Thanks,

David

Last edited by dlublink; 02-04-2006 at 11:52 AM.
 
Old 02-04-2006, 11:52 AM   #4
sipsipi
Member
 
Registered: Dec 2005
Location: Chicago
Distribution: Fedora and Redhat
Posts: 86

Rep: Reputation: 15
Thumbs up Post this project please!

This is an awesome little project that i would be interested in seeing. Can you post this, or email it to me? (The scripts and steps that is?)
 
Old 02-04-2006, 12:52 PM   #5
dlublink
Member
 
Registered: Oct 2004
Location: Canada
Distribution: Ubuntu
Posts: 329

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by sipsipi
This is an awesome little project that i would be interested in seeing. Can you post this, or email it to me? (The scripts and steps that is?)
Actually what is mentioned above is about it. I am trying to see if I can find a script that will read the email and convert it to plain text to drop HTML formatting and the like.

The only thing not mentioned above is this:

<?
$db=mysql_connect("localhost","user","password");
mysql_select_db("sms");
$email=file_get_contents("php://stdin");
$sql="insert into `emails` values('".addslashes($email)."')";
$result=mysql_query($sql);
mysql_close($db);
?>

that is /home/david/script.php

it just takes the raw email and dumps it in the database.

I am working on parsing the headers write now.

I will post my findings

David
 
Old 02-04-2006, 02:30 PM   #6
dlublink
Member
 
Registered: Oct 2004
Location: Canada
Distribution: Ubuntu
Posts: 329

Original Poster
Rep: Reputation: 30
Hey,

Well I got what I want working but I still need two things:

1. A php function or class that will filter out everything except the message text.
2. A way to return errors to postfix.

Thanks,

David
 
  


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
Setup local machine to allow lan machines to retrieve its local user mail. Brian1 Linux - Networking 3 03-30-2006 06:04 AM
Joined Domain, can't login as domain user mikeyt_333 Linux - Networking 12 08-26-2005 09:25 AM
Change user@host.domain to user@domain Wynand1 Linux - Networking 7 09-14-2004 12:56 AM
mysql doesnt create a table for each domain PurpleMotion Linux - General 0 08-01-2003 04:16 AM
Partition table - file not found emtechs Linux - Software 1 08-18-2001 02:30 PM


All times are GMT -5. The time now is 10:31 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration