LinuxQuestions.org
View the Most Wanted LQ Wiki articles.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 12-11-2006, 10:26 PM   #1
aaronvegh
LQ Newbie
 
Registered: Jun 2004
Posts: 15

Rep: Reputation: 0
Forward email to script for processing?


Hi there,
I'd like to set up a system that processes incoming mail to a specific address that I'll set up. The system might scan the subject string and act accordingly. Specifically, I'd like the system to be controlled by email.

I've had a hard time finding specific information on the 'net about doing this. I'm running Postfix on a Centos box, but I really don't want to mess with configuration of what's already a well-working system.

Can anyone offer specific advice on how to forward the fields of an email to a PHP script for processing?

Thanks in advance,
Aaron.
 
Old 12-12-2006, 01:03 AM   #2
jantman
Member
 
Registered: Nov 2005
Location: New Jersey, USA
Distribution: SuSE
Posts: 492

Rep: Reputation: 31
If you setup procmail for mail delivery, you can tell procmail to pass incoming mail to a user-defined script.
 
Old 12-12-2006, 07:21 AM   #3
aaronvegh
LQ Newbie
 
Registered: Jun 2004
Posts: 15

Original Poster
Rep: Reputation: 0
I'm not terribly familiar with procmail. I thought that a procmailrc file had to be sitting in a particular user folder to work -- and was tied to that user's email address? Where would I put it to handle delivery for a non-user-specific account?

Thanks,
Aaron.
 
Old 12-12-2006, 08:17 AM   #4
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,115

Rep: Reputation: 218Reputation: 218Reputation: 218
Hi

You can also use a .forward file in the home directory of the user on that server. Normally, you can put an email address here to have the email forwarded, but you can also specify a script if you prefix it with a "|".

For example:
You want a php script (/usr/local/bin/webmaster-email.php) to get emails sent to "webmaster@yoursite.org".
1) create the user "webmaster" on the server
2) create a /home/webmaster/.forward file and put "|/usr/local/bin/webmaster-email.php" in it (without the quotes)
3) first line of /usr/local/bin/webmaster-email.php should be #!/usr/bin/php (path to your php)
4) chmod 755 /usr/local/bin/webmaster-email.php

The reason it's good to use a system account is that it's nice to control under which user the script will run. You probably don't want to run it as root.

When the script executes, reading from stdin will give you the email.
Code:
#!/usr/bin/php
<?php
$email = "";
$fp = fopen('php:///stdin");
while ($line = fgets($fp,1000))
        $email .= $line;
fclose($fp);
//code to handle email...
?>
The email will include all headers - to find subject, just scan the lines untill you find a line starting with "Subject ".

To get the email's body, scan the lines until you find a blank line. The body is after that line.

And:
Quote:
Where would I put it to handle delivery for a non-user-specific account?
Add to /etc/aliases, e.g:
webslave: webmaster
 
Old 01-12-2011, 06:02 PM   #5
countrydj
Member
 
Registered: Jun 2009
Location: Preston, England
Distribution: Centos 6
Posts: 117

Rep: Reputation: 1
Hi Guttorm...
I know that this thread is very old, but it is the nearest thread that I have found to my problem.
If you are still monitoring this thread would you please respond.
I have a problem that I have been trying to reslove for days and can't find and answer.
Regards,

John C
 
Old 01-13-2011, 12:52 PM   #6
archtoad6
Senior Member
 
Registered: Oct 2004
Location: Houston, TX (usa)
Distribution: MEPIS, Debian, Knoppix,
Posts: 4,727
Blog Entries: 15

Rep: Reputation: 230Reputation: 230Reputation: 230
That should be: "Please respond here:"
http://www.linuxquestions.org/questi...script-855718/
That's the current theread.

Last edited by archtoad6; 01-13-2011 at 12:54 PM.
 
Old 01-13-2011, 01:31 PM   #7
countrydj
Member
 
Registered: Jun 2009
Location: Preston, England
Distribution: Centos 6
Posts: 117

Rep: Reputation: 1
Thanks moderator.

The thread that you directed me to is MINE.

However, I saw that there was a previous thread and wanted to ask Guttorm a question about it.
I can't find an email address for him or anywhere to send him a message other than here.

John C
 
Old 01-14-2011, 05:41 AM   #8
archtoad6
Senior Member
 
Registered: Oct 2004
Location: Houston, TX (usa)
Distribution: MEPIS, Debian, Knoppix,
Posts: 4,727
Blog Entries: 15

Rep: Reputation: 230Reputation: 230Reputation: 230
You're welcome.

We don't allow cross- or double- posting at LQ, so I wanted to make sure that Guttorm answered you in the appropriate place.
 
Old 01-14-2011, 06:55 AM   #9
countrydj
Member
 
Registered: Jun 2009
Location: Preston, England
Distribution: Centos 6
Posts: 117

Rep: Reputation: 1
Hi Rick...

I had no intention of cross- or double- posting. I just want to contact Guttorm.
Can you suggest how I might get in touch with Guttorm ???

Thanks,

John C
 
Old 01-14-2011, 09:02 AM   #10
archtoad6
Senior Member
 
Registered: Oct 2004
Location: Houston, TX (usa)
Distribution: MEPIS, Debian, Knoppix,
Posts: 4,727
Blog Entries: 15

Rep: Reputation: 230Reputation: 230Reputation: 230
Quote:
Originally Posted by countrydj View Post
I had no intention of cross- or double- posting.
Nor did I think you did.
I just wanted to be sure that the same issue wasn't being discussed in 2 threads, so I added a link to the main/current discussion.

I thought posting here was a reasonable way to contact Guttorm. In addition to this, you could leave a VM (Visitor Message) here:
http://www.linuxquestions.org/questi...guttorm-88727/

Last edited by archtoad6; 01-14-2011 at 09:04 AM.
 
Old 01-14-2011, 11:34 AM   #11
countrydj
Member
 
Registered: Jun 2009
Location: Preston, England
Distribution: Centos 6
Posts: 117

Rep: Reputation: 1
Thanks Rick...
 
  


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
script help for batch processing mma8x Linux - General 5 12-08-2006 01:31 AM
How to forward email when marked as SPAM matt1982 Linux - Software 1 09-11-2006 03:58 PM
How do I configure postfix master to forward all email to an email server ? hello321_1999 Linux - Software 1 11-18-2004 04:43 AM
forward root email Pete Dogg Linux - Software 5 10-29-2004 08:16 AM
Re: Forwarding email (.forward file) andy_sco123 Linux - General 3 05-24-2002 12:34 PM


All times are GMT -5. The time now is 10:43 PM.

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