Need to do an Email Pipe

14 posts / 0 new
Last post
#1 Thu, 04/28/2011 - 15:56
seozones

Need to do an Email Pipe

I need to do an email pipe for a site on my server which is running virtualmin. What are the steps to set that up? So if an email comes in, I need to store that data in the message in the body into my mysql db table. Any help would be great, thx!

Thu, 04/28/2011 - 16:13
andreychek

Howdy,

You can setup an email pipe by going into Edit Mail Aliases, click "Add an Alias to this Domain", go into the Advanced tab, and then set the Alias Destination to be "Feed to Program".

Then, just give it the path to the program it should call that can process your email.

-Eric

Thu, 04/28/2011 - 16:19
seozones

Do you mean in Postfix, right?

Thu, 04/28/2011 - 16:24
seozones

ok, I see that now. So, when you say path do you mean a php script on the server?

Thu, 04/28/2011 - 16:38
andreychek

Howdy,

So yeah, you'd set all that up in Virtualmin.

The term "path" may have been the wrong word -- you basically need to tell it what command to run in order to process the email.

If that's a PHP script in your case -- then you'd probably need to use something like:

php /path/to/php_script.php

Thu, 04/28/2011 - 16:42
seozones

ok, that took. Now, not too sure what "feed to program" does but when an email comes into the email account, will it then serve up that php script to do xyz?

Thu, 04/28/2011 - 17:47
andreychek

The "Feed to Pipe" option "pipes" the email content into STDIN of the PHP script. The PHP script then can parse it, and put it into the database.

The PHP script would of course need to know what to do with an email being piped into it.

In /etc/aliases, Virtualmin sets up a line like this:

email_alias_name: |php /path/to/php_script.php

Thu, 04/28/2011 - 17:52
seozones

There is not Feed to Pipe option in the dropdown.

Also, I set up a simple php script and placed in /public_html/parseemail.php

I created the email account in postfix but when I sent an email to that account it bounces back as undeliverable.

Thu, 04/28/2011 - 17:56
andreychek

Sorry, I meant "Feed to Program", not "Feed to Pipe".

-Eric

Thu, 04/28/2011 - 18:05
seozones

well, I tried all of that but I'm confused I guess :)

what would be the steps? I've set up an email account in postfix (not an alias, just an email account). I then created that entry for "feed to program" in virtualmin. But when I run a test and send an email to that account, the email bounces back.

Fri, 04/29/2011 - 12:56
andreychek

Is it just this one email account you're having problems with? The other ones on your server can receive email just fine?

That said -- is there a particular reason you want to use an account rather than an alias to get this up and running? If you use an alias rather than an account, you might find it a bit simpler to get things working, and you can use the steps I listed above for doing that :-)

-Eric

Wed, 05/04/2011 - 14:43
seozones

ok, I got it figured out and working! The next step is to parse the email so that it inserts into my db table. I have the following script but what do I need to do to adjust it so that it parses the email and inserts the message?

<?php
$con = mysql_connect("localhost","username","abc123");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("my_db", $con);

mysql_query("INSERT INTO Message (Message Body)
VALUES ('what goes here?')");

mysql_close($con);
?>

Wed, 05/04/2011 - 15:32
andreychek

Well, now you're getting into a fairly technical PHP coding problem :-)

That's actually a fairly involved process. My recommendation would be to look at some examples of someone else who solved the same problem... for example, there's one here that might get you started:

http://evolt.org/node/27914/

Wed, 05/04/2011 - 16:44
seozones

ok, thanks, I'll check that out.

Topic locked