Call a webservice when a message is received

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Call a webservice when a message is received

Arnau
Hi all,

  The situation I have is the following, I need to do an action
everytime a email is received. The first idea is write an script to
download the emails and then act according, but I don't like this
situation as I can have a lot of users and I'd waste a lot of polls.

  So my second approach is "tweak" postfix and everytime an email is
received by the server, then is the server who executes the action. The
action to be executed is call a webservice.

  I'm very newbie with Postfix and I don't know if is it possible to do
this easily with postfix or I have to modify the source code?

Thank you very much
--
Arnau
Reply | Threaded
Open this post in threaded view
|

Re: Call a webservice when a message is received

Gaby vanhegan

On 4 Jul 2008, at 11:37, Arnau wrote:

> The situation I have is the following, I need to do an action  
> everytime a email is received. The first idea is write an script to  
> download the emails and then act according, but I don't like this  
> situation as I can have a lot of users and I'd waste a lot of polls.
>
> So my second approach is "tweak" postfix and everytime an email is  
> received by the server, then is the server who executes the action.  
> The action to be executed is call a webservice.

Have postfix deliver messages for the specific email address to an  
alias, which pipes the messages to a script.  The script can then call  
the webservice.

/etc/aliases:
        ...
        dowebservice: "|/path/to/script.sh"

If you need it to happen for every single message that the server  
receives then you may wish to read up on the always_bcc options:

http://www.postfix.org/postconf.5.html#always_bcc

To send a copy of every mail to that email address.

G.

--
Being drunk is feeling sophisticated without being able to say it.
http://www.playr.co.uk/

Reply | Threaded
Open this post in threaded view
|

Re: Call a webservice when a message is received

Arnau
Hi Gaby,

Gaby Vanhegan wrote:

>
> On 4 Jul 2008, at 11:37, Arnau wrote:
>
>> The situation I have is the following, I need to do an action
>> everytime a email is received. The first idea is write an script to
>> download the emails and then act according, but I don't like this
>> situation as I can have a lot of users and I'd waste a lot of polls.
>>
>> So my second approach is "tweak" postfix and everytime an email is
>> received by the server, then is the server who executes the action.
>> The action to be executed is call a webservice.
>
> Have postfix deliver messages for the specific email address to an
> alias, which pipes the messages to a script.  The script can then call
> the webservice.
>
> /etc/aliases:
>     ...
>     dowebservice:    "|/path/to/script.sh"

   Is it possible to access the mail contents from inside the script?

Thanks
--
Arnau
Reply | Threaded
Open this post in threaded view
|

Re: Call a webservice when a message is received

mouss-2
Arnau wrote:

> Hi Gaby,
>
> Gaby Vanhegan wrote:
>>
>> On 4 Jul 2008, at 11:37, Arnau wrote:
>>
>>> The situation I have is the following, I need to do an action
>>> everytime a email is received. The first idea is write an script to
>>> download the emails and then act according, but I don't like this
>>> situation as I can have a lot of users and I'd waste a lot of polls.
>>>
>>> So my second approach is "tweak" postfix and everytime an email is
>>> received by the server, then is the server who executes the action.
>>> The action to be executed is call a webservice.
>>
>> Have postfix deliver messages for the specific email address to an
>> alias, which pipes the messages to a script.  The script can then
>> call the webservice.
>>
>> /etc/aliases:
>>     ...
>>     dowebservice:    "|/path/to/script.sh"
>
>   Is it possible to access the mail contents from inside the script?


the message is received via stdin (standard input). the script must read
the whole message (otherwise, you get a broekn pipe).

It may be better to use a transport instead of using aliases. see the
MAILDROP README for how to call a program using a transport. The FILTER
README also contains an example (see the "simple filter" part).

if you already have maildrop or procmail, you can use them instead.