A2 Hosting Forums

Full Version: bash script to notify about new emails
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi guys,

Have a look at the script I wrote to receive text to my cell whenever a new message comes to my mail box.  I didn't want just to redirect messages to my box at mobile provider's, because it's just 20MB small, so I wrote a simple bash script which sends notifications with informations about a sender and a subject of a new email message. Here's the contents of the script:

Code:
#!/bin/bash

MSG=$(formail)
FROM=$(echo "$MSG" | sed '/^From: */!d; s///;q')
SUBJECT=$(echo "$MSG" | sed '/^Subject: */!d; s///;q')

echo "$FROM: $SUBJECT" | mail -s New harduser@mobile-provider.com


I just set a forwarder in cPanel to pipe incoming mail to this script and it works fine for me. Try it yourselves!

Cheers,
harduser

Reference URL's