Sending email from Postfix to script

Discussion in 'Programming/Scripts' started by martinm, Feb 9, 2010.

  1. martinm

    martinm New Member

    Hi all newb here, I'm trying to add an entry in the aliases file that will pass the message body (or failing that, the whole email!) to a working perl script that sends the input to an sms. (It's for clients to tell us we REALLY have a problem via email :eek:)

    It looks like I can pipe to a command, but can't work out the syntax.

    My script takes --message="messagetext" as an argument

    so I need to somehow get postfix to do

    mysmsscript.pl --message="<the email>"

    so I imagine the alis would be something along the lines of:

    smsEmail | mysmsscript.pl --message="<the email>"


    I'm sure it's pretty trivial, but not my area of expertise:D


    Ta.
     
  2. topdog

    topdog Active Member

  3. martinm

    martinm New Member

    Thanks. I've got closer by creating a very short bash script to parameterise the message :

    #!/bin/bash
    read msg
    /usr/bin/notify-by-sms.pl --message="$msg"


    Which is called by the alias :

    sms: "|/..../email-to-sms.sh"


    This works, but I only get the from email address and Date/time info, not the message body. Is the piped input delimited in some way that separates the fields?
     
  4. topdog

    topdog Active Member

    The message body does come thru, you can use see it by doing this.

    Code:
    #!/bin/bash
    #
    cd /tmp 
    cat > input
    # do what ever you want with the message
    
    This will store the whole message in a file called input in the /tmp dir, you can then pull stuff from the message and send your sms and then remove the message. To avoid race conditions you can use this instead

    Code:
    #!/bin/bash
    #
    cd /tmp
    mkdir report-$$
    cd report-$$
    cat > input
    # do what you want with the message
    # remove temp dir
    cd /tmp
    rm -rf report-$$
    
    If you were running a server that supports sieve how ever sending sms's for each message recieved would be a piece of cake.
     
  5. martinm

    martinm New Member

    That works! I had tried print read or similar but obviously not right :confused:

    Trouble is, I now have loads of header info that is too big for an SMS. Still, I have the text to work wioth, thanks muchly.
     
  6. topdog

    topdog Active Member

    That was just showing you how to obtain the message, now that you have a full mime message of the filesystem you can do anything with it you can rip it apart get the from and to addresses and a part of the message body or just the subject and then sms it, you do not have to sms the whole email.
     
  7. mikelangelo11

    mikelangelo11 New Member

    I have use postfix pipe it work.It Sending email from Postfix to script.
     
    Last edited: Mar 30, 2010

Share This Page