Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
02-08-2005, 03:53 PM
|
#1
|
Member
Registered: Nov 2004
Distribution: RHEL 2.1, RHEL 3.0, SUSE 9.2
Posts: 31
Rep:
|
Scripting email handling
(Sorry if this is the wrong forum...)
I have a server that is sending out automated emails for a website. This is working fine. However, the powers-that-be want any undeliverable email to be flagged, and pertinent information pulled out of the message and put in a database for report generation.
My question is: is there a way to parse through received mail, search for strings, perform actions based on whether or not those strings exist, and delete all parsed messages after they've been processed?
I know I can grep through the appropriate mail spool in /var/spool/mail, but I'm nervous about trying to edit that file. I'd be less nervous editing a user's mbox file, but I don't know how to move mail from the spool to this file without actively reading it.
Any suggestions would be greatly appreciated.
matt
(fiservguy)
|
|
|
02-08-2005, 04:04 PM
|
#2
|
LQ Guru
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507
Rep:
|
Set up some sort of mail delivery system on your local box. Preferrably to an mbox. Then you can use grep and sed to extract your needed information. Or, if you use qmail or something similar, you can use the .qmail file feature of redirection to a program. I'm pretty sure other MTAs offer similar functionality.
|
|
|
02-08-2005, 04:05 PM
|
#3
|
Senior Member
Registered: Dec 2002
Location: Atlantic City, NJ
Distribution: Ubuntu & Arch
Posts: 3,503
Rep:
|
This is a tough one. What I would probably do is create a script that does the desired actions you want and run it through cron however often you want to check for these undelivered emails.
As for the scripting language to go with I would use either Perl or Python. Both can do the desired actions you want. You'll have to get good at regular expressions to parse through the contents of the mail file. I'm not sure what strings you would be looking for but pretty much anything can be done with regular expressions. Also, both languages have the ability to write to a database(i.e. mysql) and the ability to edit text files.
Am I way off base here?
|
|
|
02-08-2005, 04:21 PM
|
#4
|
Member
Registered: Nov 2004
Distribution: RHEL 2.1, RHEL 3.0, SUSE 9.2
Posts: 31
Original Poster
Rep:
|
Matir,
Thanks for the quick reply. Sendmail is loaded on the box in question; how can I (can I?) send just the mail for the user in question to a file? Would this be a sendmail.cf/mc setting or a .mailrc setting?
Crashed_Again,
You've described what I plan on doing. I just need some suggestions in how to get started. I've been boning up on my regular expressions, and I'm building a test file to play with to make sure I'm extracting what I need. Unfortunately, I'm a relatively new programmer, so this will be an exciting experience for me.
Thanks again for the quick responses.
|
|
|
03-08-2006, 01:42 AM
|
#5
|
LQ Newbie
Registered: Feb 2005
Posts: 14
Rep:
|
hi guys,
i may have a similar problem,
i need my qmail mail server to call my php script file whenever it receives a bounced email.
how do i configure it to receives bounce email and then call my php file?
thanks
|
|
|
03-08-2006, 09:24 AM
|
#6
|
Member
Registered: Nov 2004
Distribution: RHEL 2.1, RHEL 3.0, SUSE 9.2
Posts: 31
Original Poster
Rep:
|
I ulitimately went with a cron job that searches the mail file for certain keywords (specifically SMTP error codes), then extracts the pertinant information.
Set your job to run often enough and it can be "near real time" I suppose.
fiservguy
|
|
|
03-08-2006, 11:46 AM
|
#7
|
Novell CoolSolutions Editor
Registered: Jan 2006
Distribution: SUSE 9.3 - 10.0
Posts: 30
Rep:
|
Alternative solution
One thing, if I may suggest it: You might consider using a small app called 'getmail' to retrieve the mail from the server to a different location than where your 'live' email folder is. You just simply instruct getmail to not delete the messages from the server, so that sendmail or whatever can still get them. This way, you can have your own copy of the messages, and not have to mess with the live messages. You can then set up a cronjob and a script (PHP, Perl, Python, etc) to parse your messages, looking for bounces, recording them to whatever database you are using.
|
|
|
03-08-2006, 03:06 PM
|
#8
|
Senior Member
Registered: Nov 2004
Distribution: Mint, MX, antiX, SystemRescue
Posts: 2,337
|
Quote:
Originally Posted by fiservguy
I know I can grep through the appropriate mail spool in /var/spool/mail, but I'm nervous about trying to edit that file. I'd be less nervous editing a user's mbox file, but I don't know how to move mail from the spool to this file without actively reading it.
|
You could create a .forward file in the user's home directory and grab the incoming email that way.
Example:
Code:
$ cat $HOME/.forward
\username, "| /path/to/a/parser/program"
$
Replace "username" with the actual username that will be receiving the email.
The above .forward file does two things, [1] it sends incoming mail to the default destination (that's the "\username" directive before the comma) and [2] if sends a copy of the incoming mail to the STDIN of "/path/to/a/parser/program" The parser program is invoked for every new incoming email.
I have used the above technique with sendmail on Solaris, I assume it would work with other mail transport agents on Linux (you'd have to try it).
|
|
|
All times are GMT -5. The time now is 08:07 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|