LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices



Reply
 
Search this Thread
Old 07-08-2008, 03:13 PM   #1
zok
Member
 
Registered: Sep 2006
Posts: 42

Rep: Reputation: 15
Simple "Email Alert" Script/Solution


A particular office requested an email account for a particular purpose. No one is yet assigned to check it regularly, so we were asked if a group of users can be sent an email when this account receives a new message. I'm approaching it in the following way, but any feedback would be appreciated it.

We run Postfix so I added the following to our aliases file:

Quote:
testacct: "|/usr/local/bin/alert.sh", testacct
This will forward a copy of the email to /usr/local/bin/alert.sh as well as to testacct's inbox. /usr/local/bin/alert.sh does the following:

Quote:
echo "testacct@swarthmore.edu has received a new email" | /bin/mail -s "New email for testacct" user1,user2,user3
It seems to work, but I'm wondering if there's a better way to do this, if there are any security concerns (only sysadmins have shell access to the mail server); or maybe there's already a script out there that does this, etc? Thanks for any feedback.
 
Old 07-08-2008, 04:17 PM   #2
forrestt
Senior Member
 
Registered: Mar 2004
Location: Cary, NC, USA
Distribution: Fedora, Kubuntu, RedHat, CentOS, SuSe
Posts: 1,288

Rep: Reputation: 99
Why don't you just put the user1, user2, user3 in the aliases file for testacct?

Code:
testacct:        user1, user2, user3, testacct
You can then set a filter on your email client to filter mail that is sent to testacct. This will leave all your configurations in one place and will use a standard, tested method.

HTH

Forrest
 
Old 07-08-2008, 04:30 PM   #3
zok
Member
 
Registered: Sep 2006
Posts: 42

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by forrestt View Post
Why don't you just put the user1, user2, user3 in the aliases file for testacct?
Yeah, that would be easy, right? Except they don't want that. They want the emails destined for testacct to only go to testacct, not all the users. I guess so they can keep everything centralized.
 
Old 07-08-2008, 04:38 PM   #4
marozsas
Senior Member
 
Registered: Dec 2005
Location: Campinas/SP - Brazil
Distribution: SuSE, RHEL, Fedora, Ubuntu
Posts: 1,393
Blog Entries: 1

Rep: Reputation: 64
my two cents: What about leave the e-mail account as a regular one. No re-directions at all.
In the client side, configure a second account to get e-mails for this account using IMAP, so several clients can connect to it at same time and all get the same e-mail.
The assigned users 1, 2 and 3, will have two independent e-mails boxes and the replies will come from testacct, and the Sent/deleted e-mail will be centralized in the imap server, not in the local disk.
 
Old 07-08-2008, 04:47 PM   #5
forrestt
Senior Member
 
Registered: Mar 2004
Location: Cary, NC, USA
Distribution: Fedora, Kubuntu, RedHat, CentOS, SuSe
Posts: 1,288

Rep: Reputation: 99
This is what happens when you have marketing folk perform systems engineering. You should tell them that every time someone from marketing attempts to do systems engineering a kitty dies.

Forrest
 
Old 07-08-2008, 07:33 PM   #6
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 59
Here's a way to use the system as it was designed:

1) Create an alias or virtual alias testnotify which includes the users that you want to notify.of new mail arrival.
2) Remove the .forwards you have for testacct.

Here's how you generate your message:

cat mymessage | sendmail -f testnofify@yourdomain.com -N success testacct@yourdomain.com

testnotify@yourdomain.com will get DNS (delivery status notification) on successful delivery to testacct@yourdomain.com, which only gets mymessage.
 
Old 07-09-2008, 01:58 PM   #7
zok
Member
 
Registered: Sep 2006
Posts: 42

Original Poster
Rep: Reputation: 15
Hmm...I thought I replied to this earlier. Anyway...So, not unexpectedly I've gotten more specific instructions. They would like the sender included in the alert. So it looks like I'll be using the method I mentioned earlier. So far I got it working in the following way. The following is in the Postfix aliases file:

Quote:
testacct: "|/usr/local/bin/alert.sh", testacct
/usr/local/bin/alert.sh has the following:

Quote:
sender="Unknown Sender"
while read message; do
if echo $message | grep "From:" > /dev/null; then
sender=$message
fi
done

echo "testacct has received an email -- $sender" | /bin/mail -s "New email for investments" user1, user2, user3
I know this isn't the best solution, though. For example, if there's a "From:" in the message, it'll report an incorrect sender. Any suggestions on how to improve this?
 
Old 07-09-2008, 02:13 PM   #8
Mr. C.
Senior Member
 
Registered: Jun 2008
Posts: 2,529

Rep: Reputation: 59
Any solution that works reliably for your situation is good enough.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
bash script: using "select" to show multi-word options? (like "option 1"/"o zidane_tribal Programming 6 03-21-2013 11:35 AM
Simple bash script "unexpected end of line error" snowman81 Programming 11 11-11-2007 10:31 AM
Proposed solution for "status" (aka "problem solved") indicator demerson3 LQ Suggestions & Feedback 12 04-08-2006 03:15 PM
Simple "service" script for dealing with rc files arobinson74 Slackware 0 09-07-2004 12:43 AM
Require solution for an intersting "email related" problem ganninu Linux - General 3 08-18-2003 11:43 AM


All times are GMT -5. The time now is 05:25 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration