Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Monitoring new mail in Cyrus-IMAP accounts

Posted on 2006-07-12
7
Medium Priority
?
346 Views
Last Modified: 2008-02-01
  Hi!

I need a Perl (cron job) script to monitor new mail on several email accounts on my Postfix/Cyrus-IMAP server.
This job should count new messages (unread messages) and send the result to specific email address.
How do I do this ?

Regards,
  Tomas Helgi
0
Comment
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
7 Comments
 
LVL 24

Expert Comment

by:slyong
ID: 17089556
Hi Tomas,

I am not sure how you want the total solution to be.  I would use fetchmail for this task:

1) create ~/.fetchmailrc with something like:
poll imap.your.mail.server with proto IMAP user youruserid password yourpassword is youruseridonlocal

2) create a Perl script like:
#!/usr/bin/perl
my $result   = `fetchmail -c`;
chop $result;

my @mailinfo = split(/ /, $result);
my $unread   = $mailinfo[0] - substr($mailinfo[2],1);

open (MAIL, "|/usr/sbin/sendmail -t ");
  print MAIL "From: noreply\@yourdomain.com\n";
  print MAIL "To: receiver\@receiverdomain.com\n";
  print MAIL "Content-Type: text/plain\n";
  print MAIL "Subject: New Mail Notice\n";
  print MAIL "You have $unread new mail(s) in $mailinfo[7]\n";
close (MAIL);
0
 
LVL 40

Expert Comment

by:noci
ID: 17095816
Or access the IMAP store directly
http://www.cpan.org/modules/by-module/Mail/Mail-IMAPClient-2.2.9.readme

The imapsync tool uses it to synchronise imap stores.
(ie transplant messages as the are from one to another store.)
0
 
LVL 24

Expert Comment

by:slyong
ID: 17196443
I think that the fetchmail + Perl Script that I provided pretty much covered what is needed (i.e. check how many mail in the mailbox and send an email).  The solution is provided so the points should be rewarded accordingly.
0
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 
LVL 25

Author Comment

by:Tomas Helgi Johannsson
ID: 17210497
This is not what I was looking for.
This is just for one single account.

Regards,
  Tomas Helgi
0
 
LVL 24

Accepted Solution

by:
slyong earned 300 total points
ID: 17210506
1) create multiple fetchmail configuration files with something like:

account1.fetchmailrc
poll imap.your.mail.server with proto IMAP user youruserid1 password yourpassword1 is youruseridonlocal1

account2.fetchmailrc
poll imap.your.mail.server with proto IMAP user youruserid2 password yourpassword2 is youruseridonlocal2


2) create a Perl script like:
#!/usr/bin/perl
my $result   = `fetchmail -c -f account1.fetchmailrc`;
chop $result;

my @mailinfo = split(/ /, $result);
my $unread   = $mailinfo[0] - substr($mailinfo[2],1);

open (MAIL, "|/usr/sbin/sendmail -t ");
  print MAIL "From: noreply\@yourdomain.com\n";
  print MAIL "To: receiver1\@receiverdomain.com\n";
  print MAIL "Content-Type: text/plain\n";
  print MAIL "Subject: New Mail Notice\n";
  print MAIL "You have $unread new mail(s) in $mailinfo[7]\n";
close (MAIL);

my $result   = `fetchmail -c -f account2.fetchmailrc`;
chop $result;

my @mailinfo = split(/ /, $result);
my $unread   = $mailinfo[0] - substr($mailinfo[2],1);

open (MAIL, "|/usr/sbin/sendmail -t ");
  print MAIL "From: noreply\@yourdomain.com\n";
  print MAIL "To: receiver2\@receiverdomain.com\n";
  print MAIL "Content-Type: text/plain\n";
  print MAIL "Subject: New Mail Notice\n";
  print MAIL "You have $unread new mail(s) in $mailinfo[7]\n";
close (MAIL);
0
 
LVL 25

Author Comment

by:Tomas Helgi Johannsson
ID: 17211243
Hmm, ok this would go with slight modifications.

Thanks.

Regards,
   Tomas Helgi
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question