Forum Moderators: coopster

Message Too Old, No Replies

Capturing an email reply via a script

Looking for a direction

         

jamesa

10:06 am on Dec 9, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Larry Page (from this [business2.com]):
We did a simple thing that in retrospect was brilliant: We wrote a program that asks every engineer what they did every week. It sends them e-mail on Monday, and concatenates the e-mails together in a document that everyone can read. And it then sends that out to everyone and shames those who did not answer by putting them on the top of the list. It has run reliably every week since we started, so for every week of our company's history we have a record of what everyone did.

Basically I want to write a script just like that. Question: what's the best way to capture the email replies so I can process them? Create a script that acts as a POP or IMAP client? Via the filesystem somehow (I'm using qmail)? Is there a another way?

If anyone can point me in the right direction...

P.S. - Been doing about of CLI scripts in PHP lately and loving it :)

rubenski

6:01 pm on Dec 9, 2003 (gmt 0)

10+ Year Member



You don't necessarily have to use email for this. Perhaps it would be easier if you created an online form that submits the contents to a simple Mysql db?

I can mail (or post) some examples if you like.

jonknee

3:32 am on Dec 10, 2003 (gmt 0)

10+ Year Member



I would use POP over IMAP and just use CRON to check the mail every Tuesday (or whatever fits your use of the app). Sounds like a really neat application.

As Rubenski suggested, you could do this from a web based app. You could write a script to mail everyone on Monday with a link to the web page... A lot less coding that way.

NickCoons

3:41 am on Dec 10, 2003 (gmt 0)

10+ Year Member



With sendmail, you can configure it to execute a script (a PHP script using the CLI, for instance) when it receives an email at a particular address. I imagine the same thing can be configured on qmail.

jamesa

4:55 pm on Dec 10, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ahhh, thanks NickCoons. Good to know, definitely gives me a solid direction. And that reminds me that majordomo and the like do the same sort of thing, which is another place I can look. But if anyone has any more specifics or even suggestions on what to Google for, don't be shy :).

And not that the HTML form wouldn't be easier, just that acceptance among the userbase will probably be better if email is the "interface" (not to mention it would be a cool thing to know how to do <-- the real reason, hehe). I appreciate the suggestions, though, keep them coming.

NickCoons

5:01 pm on Dec 10, 2003 (gmt 0)

10+ Year Member



I found the instructions here in my bookmarks. This page includes instructions explaining how to do this in sendmail, exim, and qmail:

Incoming Mail and PHP [evolt.org]

httpwebwitch

6:25 pm on Dec 10, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I found the instructions here

I've been wondering if I could create a script that would adjust a mailing list when someone sends a reply to a specific address, such as unsubscribe@mydomain.com. I had no idea where to start. I'm working on a subscription/e-newsletter mailing system, and that is one of the things I was worried about.

This is going to take a lot of experimentation and a lot of calls to my server admin guy. If anyone has any pre-cooked solutions, please share!

thanks!

Timotheos

8:45 pm on Dec 10, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Nick's link is pretty cool but it requires PHP compiled as a CGI binary. I'm not too up on that. Can you have PHP compiled as an Apache module and a CGI binary at the same time?

If it was me I'd be looking at the POP3 classes at sourceforge. There's also all sorts of PHP web based mail programs that somehow can grab an email off a POP3 account. If it was me I'd be figuring out how they do it.

jamesa

8:49 pm on Dec 10, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



NickCoons:
That's all there is to it? Awesome. Nice link, thank you.

httpwebwitch:
Should be pretty easy to do. If you're looking for a pre-written script, try hotscripts or any of the other script repositories. Otherwise let us know where you're getting hung up.

NickCoons

8:54 pm on Dec 10, 2003 (gmt 0)

10+ Year Member



Timotheos,

<Nick's link is pretty cool but it requires PHP compiled as a CGI binary. I'm not too up on that.>

I think that is enabled by default in PHP =>4.3.

<Can you have PHP compiled as an Apache module and a CGI binary at the same time?>

Yes.. having the command-line interface compiled just means that you've created a binary called "php", usually /usr/bin/php. You can have either the CLI compiled, the Apache module, or both. They don't interfere with each other, and creating scripts for it works just like creating a script in Perl (the first line is the path to the php binary).

bobbee

12:55 am on Dec 11, 2003 (gmt 0)

10+ Year Member



I did something very similar to this. I set up a pop address to receive mails for processing with PHP. I had it set up to run as a cron job.

The following code is the framework of what I used:

# ******************************************************************
$imap_stream = imap_open($mailbox, $userid, $userpassword);
if(!$imap_stream) die("Error opening a stream to the IMAP server! " . imap_last_error());
$mssg_count = imap_num_msg($imap_stream);
if ($mssg_count){
for($the_mssg_id=0; $the_mssg_id<=$mssg_count; ++$the_mssg_id){#loop for each message

# process messages here

$this_header = imap_fetchheader ($imap_stream,$the_mssg_id,FT_UID);
}
}else{
echo ("There are NO messages");
}
if(!imap_close($imap_stream)) die("Error closing the stream!");
# ******************************************************************

I hope this helps.

Bob