Go Back   HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials > Linux Forums > Programming/Scripts

Do you like HowtoForge? Please consider supporting us by becoming a subscriber.
Reply
 
Thread Tools Display Modes
  #1  
Old 9th February 2010, 15:59
martinm martinm is offline
Junior Member
 
Join Date: Feb 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Sending email from Postfix to script

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 )

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


Ta.
Reply With Quote
Sponsored Links
  #2  
Old 9th February 2010, 17:43
topdog topdog is offline
Senior Member
 
Join Date: Jan 2008
Location: South Africa
Posts: 1,352
Thanks: 0
Thanked 153 Times in 150 Posts
Default

Use the postfix pipe, the documentation is here http://www.postfix.org/pipe.8.html
__________________
----
http://www.topdog.za.net - Got Linux problems ? - I can help.
http://www.baruwa.org - Try it.
Reply With Quote
  #3  
Old 12th March 2010, 15:26
martinm martinm is offline
Junior Member
 
Join Date: Feb 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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?
Reply With Quote
  #4  
Old 12th March 2010, 15:38
topdog topdog is offline
Senior Member
 
Join Date: Jan 2008
Location: South Africa
Posts: 1,352
Thanks: 0
Thanked 153 Times in 150 Posts
Default

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.
__________________
----
http://www.topdog.za.net - Got Linux problems ? - I can help.
http://www.baruwa.org - Try it.
Reply With Quote
  #5  
Old 12th March 2010, 15:52
martinm martinm is offline
Junior Member
 
Join Date: Feb 2010
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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

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.
Reply With Quote
  #6  
Old 12th March 2010, 15:56
topdog topdog is offline
Senior Member
 
Join Date: Jan 2008
Location: South Africa
Posts: 1,352
Thanks: 0
Thanked 153 Times in 150 Posts
Default

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.
__________________
----
http://www.topdog.za.net - Got Linux problems ? - I can help.
http://www.baruwa.org - Try it.
Reply With Quote
  #7  
Old 30th March 2010, 10:46
mikelangelo11 mikelangelo11 is offline
Junior Member
 
Join Date: Mar 2010
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
 
Default

I have use postfix pipe it work.It Sending email from Postfix to script.
__________________
nintendo r4

Last edited by mikelangelo11; 30th March 2010 at 10:52.
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Postfix Quota Notification Email Script asyadiqin Installation/Configuration 14 23rd July 2010 13:35
Undelivered Mail Returned to Sender Error202 General 5 7th May 2009 11:14
hotmail rejects outgoing email nzimas Server Operation 3 1st May 2009 03:39
CentoS doesn't send the emails vaio1 Installation/Configuration 18 5th November 2008 17:51
email migration to postfix tsu pinoy Server Operation 1 28th October 2008 14:48


All times are GMT +2. The time now is 18:57.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.