Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: exim: users

Save a mail and then execute a script

 

 

exim users RSS feed   Index | Next | Previous | View Threaded


julien.balmont at gmail

May 13, 2008, 12:20 AM

Post #1 of 11 (391 views)
Permalink
Save a mail and then execute a script

Hi all, thanks for helping me.

I'm not an expert in Exim, but I now understand how it works, and i'm trying
to do the following:
an email arrives, it is saved to a file, then an external PHP script is
called.

I've already made two routers and two transports (see below).
My issue with what I made:
The mail goes through router my_file, then to transport local_copy_incoming
but never goes to router my_script.

Is there a way to do what I want to do? Please help, i'm searching for a
long time ago now.

//ROUTERS

my_file:
driver = accept
domains = domain.com
no_expn
retry_use_local_part
transport = local_copy_incoming

my_script:
driver = accept
domains = domain.com
no_expn
retry_use_local_part
transport = to_my_script

//TRANSPORTS
local_copy_incoming:
driver = appendfile
delivery_date_add
envelope_to_add
return_path_add
group = web
user = web
mode = 0755
file = /var/www/mailspool/$message_exim_id

to_my_script:
driver = pipe
command = /usr/bin/php5 -f /var/www/dev/script.php $message_exim_id
$local_part $domain $h_subject
home_directory = /tmp
current_directory = /tmp
user = web
group = web
log_output = true
return_fail_output = true
return_path_add = false
--
## List details at http://lists.exim.org/mailman/listinfo/exim-users
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/


wbh at conducive

May 13, 2008, 12:36 AM

Post #2 of 11 (375 views)
Permalink
Re: Save a mail and then execute a script [In reply to]

Julien Balmont wrote:
> Hi all, thanks for helping me.
>
> I'm not an expert in Exim, but I now understand how it works, and i'm trying
> to do the following:
> an email arrives, it is saved to a file, then an external PHP script is
> called.
>
> I've already made two routers and two transports (see below).
> My issue with what I made:
> The mail goes through router my_file, then to transport local_copy_incoming
> but never goes to router my_script.
>
> Is there a way to do what I want to do? Please help, i'm searching for a
> long time ago now.

As soon as the first router is matched, traversal ceases and processing
jumps to the transport dsignated by that router.

Place an 'unseen' after a router if you want the stored message data to
be processed again before being 'used up' by the first delivery.

See below.

>
> //ROUTERS
>
> my_file:
> driver = accept
> domains = domain.com
> no_expn
> retry_use_local_part
> transport = local_copy_incoming
>
unseen

> my_script:
> driver = accept
> domains = domain.com
> no_expn
> retry_use_local_part
> transport = to_my_script
>

*snip*

FWIW, Exim can hand-off to anything executable, stoabel, or sideways,
but PHP is not the greatest of choices for this sort of work.

Fisrt - Exim can probably do what you want with its own resources.

Next best might be perl, with which Exim is more 'comfortable' fit.

It isn't just about your language preferences.

It is also about how variables and strings and character encoding and
such are handled - e.g. - 'not always the same way'.

HTH,

Bill

--
## List details at http://lists.exim.org/mailman/listinfo/exim-users
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/


julien.balmont at gmail

May 13, 2008, 1:01 AM

Post #3 of 11 (377 views)
Permalink
Re: Save a mail and then execute a script [In reply to]

Hi Bill, thanks for your wuick answer.

I've tested what you've proposed, and it worked. But I meet another issue.
The script I'm calling ios supposed to open the saved file and check its
content.

But at the moment the script is called, the file doesn't seem to be saved
yet. Do you have an idea?

Thanks for your advice about Perl and not PHP, I'll talk about it to my
colleagues to make them change theinr mind :)


On Tue, May 13, 2008 at 9:36 AM, W B Hacker <wbh[at]conducive.org> wrote:

> Julien Balmont wrote:
> > Hi all, thanks for helping me.
> >
> > I'm not an expert in Exim, but I now understand how it works, and i'm
> trying
> > to do the following:
> > an email arrives, it is saved to a file, then an external PHP script is
> > called.
> >
> > I've already made two routers and two transports (see below).
> > My issue with what I made:
> > The mail goes through router my_file, then to transport
> local_copy_incoming
> > but never goes to router my_script.
> >
> > Is there a way to do what I want to do? Please help, i'm searching for a
> > long time ago now.
>
> As soon as the first router is matched, traversal ceases and processing
> jumps to the transport dsignated by that router.
>
> Place an 'unseen' after a router if you want the stored message data to
> be processed again before being 'used up' by the first delivery.
>
> See below.
>
> >
> > //ROUTERS
> >
> > my_file:
> > driver = accept
> > domains = domain.com
> > no_expn
> > retry_use_local_part
> > transport = local_copy_incoming
> >
> unseen
>
> > my_script:
> > driver = accept
> > domains = domain.com
> > no_expn
> > retry_use_local_part
> > transport = to_my_script
> >
>
> *snip*
>
> FWIW, Exim can hand-off to anything executable, stoabel, or sideways,
> but PHP is not the greatest of choices for this sort of work.
>
> Fisrt - Exim can probably do what you want with its own resources.
>
> Next best might be perl, with which Exim is more 'comfortable' fit.
>
> It isn't just about your language preferences.
>
> It is also about how variables and strings and character encoding and
> such are handled - e.g. - 'not always the same way'.
>
> HTH,
>
> Bill
>
> --
> ## List details at http://lists.exim.org/mailman/listinfo/exim-users
> ## Exim details at http://www.exim.org/
> ## Please use the Wiki with this list - http://wiki.exim.org/
>
--
## List details at http://lists.exim.org/mailman/listinfo/exim-users
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/


julien.balmont at gmail

May 13, 2008, 3:09 AM

Post #4 of 11 (372 views)
Permalink
Re: Save a mail and then execute a script [In reply to]

BTW, I'm afraid the file is saved only after the script is called.
Is there a way to avoid this behaviour?

Or to do it simplier?

Thanks!!

On Tue, May 13, 2008 at 10:01 AM, Julien Balmont <julien.balmont[at]gmail.com>
wrote:

> Hi Bill, thanks for your wuick answer.
>
> I've tested what you've proposed, and it worked. But I meet another issue.
> The script I'm calling ios supposed to open the saved file and check its
> content.
>
> But at the moment the script is called, the file doesn't seem to be saved
> yet. Do you have an idea?
>
> Thanks for your advice about Perl and not PHP, I'll talk about it to my
> colleagues to make them change theinr mind :)
>
>
>
> On Tue, May 13, 2008 at 9:36 AM, W B Hacker <wbh[at]conducive.org> wrote:
>
> > Julien Balmont wrote:
> > > Hi all, thanks for helping me.
> > >
> > > I'm not an expert in Exim, but I now understand how it works, and i'm
> > trying
> > > to do the following:
> > > an email arrives, it is saved to a file, then an external PHP script
> > is
> > > called.
> > >
> > > I've already made two routers and two transports (see below).
> > > My issue with what I made:
> > > The mail goes through router my_file, then to transport
> > local_copy_incoming
> > > but never goes to router my_script.
> > >
> > > Is there a way to do what I want to do? Please help, i'm searching for
> > a
> > > long time ago now.
> >
> > As soon as the first router is matched, traversal ceases and processing
> > jumps to the transport dsignated by that router.
> >
> > Place an 'unseen' after a router if you want the stored message data to
> > be processed again before being 'used up' by the first delivery.
> >
> > See below.
> >
> > >
> > > //ROUTERS
> > >
> > > my_file:
> > > driver = accept
> > > domains = domain.com
> > > no_expn
> > > retry_use_local_part
> > > transport = local_copy_incoming
> > >
> > unseen
> >
> > > my_script:
> > > driver = accept
> > > domains = domain.com
> > > no_expn
> > > retry_use_local_part
> > > transport = to_my_script
> > >
> >
> > *snip*
> >
> > FWIW, Exim can hand-off to anything executable, stoabel, or sideways,
> > but PHP is not the greatest of choices for this sort of work.
> >
> > Fisrt - Exim can probably do what you want with its own resources.
> >
> > Next best might be perl, with which Exim is more 'comfortable' fit.
> >
> > It isn't just about your language preferences.
> >
> > It is also about how variables and strings and character encoding and
> > such are handled - e.g. - 'not always the same way'.
> >
> > HTH,
> >
> > Bill
> >
> > --
> > ## List details at http://lists.exim.org/mailman/listinfo/exim-users
> > ## Exim details at http://www.exim.org/
> > ## Please use the Wiki with this list - http://wiki.exim.org/
> >
>
>
--
## List details at http://lists.exim.org/mailman/listinfo/exim-users
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/


pv0001 at dynapic

May 13, 2008, 4:20 AM

Post #5 of 11 (372 views)
Permalink
Re: Save a mail and then execute a script [In reply to]

am 13.05.2008 12:09 schrieb Julien Balmont:
> BTW, I'm afraid the file is saved only after the script is called.
> Is there a way to avoid this behaviour?

My transport looks like ...

script_transport:
driver = pipe
envelope_to_add
delivery_date_add
user = userxyz
group = groupxyz
command = /scriptpath/perlscript -para1=y -para2=y -para2=n - -

The essential part in my script: read piped message from STDIN and save
it in a file ...

open( MAIL, "> $filename" );
while( <> ) { print MAIL $_; }
close( MAIL );

Now I could do whatever I want on the stored copy of the message.

Do you rely on Exim to store the message or do you read the pipe?

Cheers,
Peter

--
## List details at http://lists.exim.org/mailman/listinfo/exim-users
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/


julien.balmont at gmail

May 13, 2008, 5:23 AM

Post #6 of 11 (367 views)
Permalink
Re: Save a mail and then execute a script [In reply to]

Peter, you're my hero :)

Thanks !!!

On Tue, May 13, 2008 at 1:20 PM, Peter Velan <pv0001[at]dynapic.net> wrote:

> am 13.05.2008 12:09 schrieb Julien Balmont:
> > BTW, I'm afraid the file is saved only after the script is called.
> > Is there a way to avoid this behaviour?
>
> My transport looks like ...
>
> script_transport:
> driver = pipe
> envelope_to_add
> delivery_date_add
> user = userxyz
> group = groupxyz
> command = /scriptpath/perlscript -para1=y -para2=y -para2=n - -
>
> The essential part in my script: read piped message from STDIN and save
> it in a file ...
>
> open( MAIL, "> $filename" );
> while( <> ) { print MAIL $_; }
> close( MAIL );
>
> Now I could do whatever I want on the stored copy of the message.
>
> Do you rely on Exim to store the message or do you read the pipe?
>
> Cheers,
> Peter
>
> --
> ## List details at http://lists.exim.org/mailman/listinfo/exim-users
> ## Exim details at http://www.exim.org/
> ## Please use the Wiki with this list - http://wiki.exim.org/
>
--
## List details at http://lists.exim.org/mailman/listinfo/exim-users
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/


pv0001 at dynapic

May 13, 2008, 5:35 AM

Post #7 of 11 (368 views)
Permalink
Re: Save a mail and then execute a script [In reply to]

am 13.05.2008 14:23 schrieb Julien Balmont:
> Peter, you're my hero :)

:-[

I'm curious: Which part of my message was helpfull?

Peter

PS: Type a response *below* the quoted material you're responding to,
so it reads like a conversation. Please don't top-post!
<http://www.faqs.org/faqs/comics/xbooks/readpost/section-4.html>

> On Tue, May 13, 2008 at 1:20 PM, Peter Velan <pv0001[at]dynapic.net> wrote:
>
>> am 13.05.2008 12:09 schrieb Julien Balmont:
>> > BTW, I'm afraid the file is saved only after the script is called.
>> > Is there a way to avoid this behaviour?
>>
>> My transport looks like ...
>>
>> script_transport:
>> driver = pipe
>> envelope_to_add
>> delivery_date_add
>> user = userxyz
>> group = groupxyz
>> command = /scriptpath/perlscript -para1=y -para2=y -para2=n - -
>>
>> The essential part in my script: read piped message from STDIN and save
>> it in a file ...
>>
>> open( MAIL, "> $filename" );
>> while( <> ) { print MAIL $_; }
>> close( MAIL );
>>
>> Now I could do whatever I want on the stored copy of the message.
>>
>> Do you rely on Exim to store the message or do you read the pipe?
>>
>> Cheers,
>> Peter


--
## List details at http://lists.exim.org/mailman/listinfo/exim-users
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/


julien.balmont at gmail

May 13, 2008, 5:39 AM

Post #8 of 11 (368 views)
Permalink
Re: Save a mail and then execute a script [In reply to]

The part with STDIN.
i hadn't found yet how to retrieve the message from EXIM. I had not thought
about STDIN, this was helpful.

Thanks again

On Tue, May 13, 2008 at 2:35 PM, Peter Velan <pv0001[at]dynapic.net> wrote:

> am 13.05.2008 14:23 schrieb Julien Balmont:
> > Peter, you're my hero :)
>
> :-[
>
> I'm curious: Which part of my message was helpfull?
>
> Peter
>
> PS: Type a response *below* the quoted material you're responding to,
> so it reads like a conversation. Please don't top-post!
> <http://www.faqs.org/faqs/comics/xbooks/readpost/section-4.html>
>
> > On Tue, May 13, 2008 at 1:20 PM, Peter Velan <pv0001[at]dynapic.net> wrote:
> >
> >> am 13.05.2008 12:09 schrieb Julien Balmont:
> >> > BTW, I'm afraid the file is saved only after the script is called.
> >> > Is there a way to avoid this behaviour?
> >>
> >> My transport looks like ...
> >>
> >> script_transport:
> >> driver = pipe
> >> envelope_to_add
> >> delivery_date_add
> >> user = userxyz
> >> group = groupxyz
> >> command = /scriptpath/perlscript -para1=y -para2=y -para2=n - -
> >>
> >> The essential part in my script: read piped message from STDIN and save
> >> it in a file ...
> >>
> >> open( MAIL, "> $filename" );
> >> while( <> ) { print MAIL $_; }
> >> close( MAIL );
> >>
> >> Now I could do whatever I want on the stored copy of the message.
> >>
> >> Do you rely on Exim to store the message or do you read the pipe?
> >>
> >> Cheers,
> >> Peter
>
>
> --
> ## List details at http://lists.exim.org/mailman/listinfo/exim-users
> ## Exim details at http://www.exim.org/
> ## Please use the Wiki with this list - http://wiki.exim.org/
>
--
## List details at http://lists.exim.org/mailman/listinfo/exim-users
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/


wbh at conducive

May 13, 2008, 11:25 AM

Post #9 of 11 (359 views)
Permalink
Re: Save a mail and then execute a script [In reply to]

Julien Balmont wrote:
> Hi Bill, thanks for your wuick answer.
>
> I've tested what you've proposed, and it worked. But I meet another issue.
> The script I'm calling ios supposed to open the saved file and check its
> content.
>
> But at the moment the script is called, the file doesn't seem to be saved
> yet. Do you have an idea?
>

With files writes, it cannot be guaranteed to be where you expect it to
be until Exim *finishes* the delivery.

You can watch this happen if you have

log-selector = +all (for test)

Each active router/transport set will create a time-stamped log line.

Back that 'log-selector = ' down to a more selective subset for
production, ELSE remove it and use the defaults. Otherwise, you can
fill the HD with logs.


NB: SQL inserts and selects *are* handled in near-real time.

So, too certain types of executables.

But that alone is not reason enough to complicate life if you do not
have to.

> Thanks for your advice about Perl and not PHP, I'll talk about it to my
> colleagues to make them change theinr mind :)
>
>

Each has its strengths.

But you can probably do what you want without *any* external scripting.

*snip*


--
## List details at http://lists.exim.org/mailman/listinfo/exim-users
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/


wbh at conducive

May 13, 2008, 11:39 AM

Post #10 of 11 (360 views)
Permalink
Re: Save a mail and then execute a script [In reply to]

Julien Balmont wrote:
> BTW, I'm afraid the file is saved only after the script is called.
> Is there a way to avoid this behaviour?
>
> Or to do it simplier?
>
> Thanks!!

'Simpler'? Almost certainly.

First - what is the *end* result you are trying to accomplish?

My bet is that it has already been done, and more than once, and in more
than one way - by others on this list.

That wheel may not need to be reinvented.

Tell us the 'big picture'.

Bill

*snip*


--
## List details at http://lists.exim.org/mailman/listinfo/exim-users
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/


jori.hamalainen at teliasonera

May 14, 2008, 4:33 AM

Post #11 of 11 (340 views)
Permalink
Re: Save a mail and then execute a script [In reply to]

Just a though what I am doing on my setup..

Do you need to save file and run the script at 'routers' level. I believe then script would be ran several times if there is CC-field in email or in general a multiple recipients. But it depends what you need to do.

What I am doing is on "data ACL" I have a ${run} with my script. Just give variable $message_id as a parameter, then search from spool directory $message_id-H and $message_id-D files and do what ever you like. And script is ran once when message comes in.

[as a framework, not syntax checked or tested]
warn log_message = running a script to $message-id
domains|sender - preconditions
condition = ${run...
or
set acl_mscriptoutput = ${run..

- Jori

-----Original Message-----
From: exim-users-bounces[at]exim.org [mailto:exim-users-bounces[at]exim.org] On Behalf Of Julien Balmont
Sent: 13. toukokuuta 2008 15:40
To: Peter Velan
Cc: exim users
Subject: Re: [exim] Save a mail and then execute a script


The part with STDIN.
i hadn't found yet how to retrieve the message from EXIM. I had not thought about STDIN, this was helpful.

Thanks again

On Tue, May 13, 2008 at 2:35 PM, Peter Velan <pv0001[at]dynapic.net> wrote:

> am 13.05.2008 14:23 schrieb Julien Balmont:
> > Peter, you're my hero :)
>
> :-[
>
> I'm curious: Which part of my message was helpfull?
>
> Peter
>
> PS: Type a response *below* the quoted material you're responding to,
> so it reads like a conversation. Please don't top-post!
> <http://www.faqs.org/faqs/comics/xbooks/readpost/section-4.html>
>
> > On Tue, May 13, 2008 at 1:20 PM, Peter Velan <pv0001[at]dynapic.net> wrote:
> >
> >> am 13.05.2008 12:09 schrieb Julien Balmont:
> >> > BTW, I'm afraid the file is saved only after the script is called.
> >> > Is there a way to avoid this behaviour?
> >>
> >> My transport looks like ...
> >>
> >> script_transport:
> >> driver = pipe
> >> envelope_to_add
> >> delivery_date_add
> >> user = userxyz
> >> group = groupxyz
> >> command = /scriptpath/perlscript -para1=y -para2=y -para2=n - -
> >>
> >> The essential part in my script: read piped message from STDIN and
> >> save it in a file ...
> >>
> >> open( MAIL, "> $filename" );
> >> while( <> ) { print MAIL $_; }
> >> close( MAIL );
> >>
> >> Now I could do whatever I want on the stored copy of the message.
> >>
> >> Do you rely on Exim to store the message or do you read the pipe?
> >>
> >> Cheers,
> >> Peter
>
>
> --
> ## List details at http://lists.exim.org/mailman/listinfo/exim-users
> ## Exim details at http://www.exim.org/ ## Please use the Wiki with
> this list - http://wiki.exim.org/
>
--
## List details at http://lists.exim.org/mailman/listinfo/exim-users
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/

--
## List details at http://lists.exim.org/mailman/listinfo/exim-users
## Exim details at http://www.exim.org/
## Please use the Wiki with this list - http://wiki.exim.org/

exim users RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact lists@gossamer-threads.com
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.