Zimbra offers Open Source email server software and shared calendar for Linux and the Mac
Go Back   Zimbra :: Forums > Zimbra Collaboration Suite > Administrators

Welcome to the Zimbra :: Forums!
Welcome, if you would like to post a comment please register. We also encourage you to explore all things Zimbra with our team and members of the community.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-08-2009, 08:36 AM
Junior Member
 
Posts: 5
Default [SOLVED] Running a script / program on successful delivery

Hi there,

I want to run a script *after* each successful message delivery. This is to implement a custom delivery notification system and other things that can't be achieved by standard means.

All I need is to run a program which takes the email address as an argument.

I can code, so if this needs developing some hook/plugin, that also is ok.

Thanks in advance.

Anuradha
Reply With Quote
  #2 (permalink)  
Old 11-08-2009, 11:05 AM
Junior Member
 
Posts: 5
Default

I managed to get this done by hacking zmlogger. Couldn't run my own script by editing logswatchrc, which would have been neater. Here is what I added to zmlogger.

Code:
--- zmlogger.orig       2009-11-08 23:01:36.000000000 +0530
+++ zmlogger    2009-11-08 23:17:05.000000000 +0530
@@ -468,6 +468,13 @@
             next if (!scalar @match);
             ($csv_file, $csv_confirm, $headers, $data) = @match;
             die "$csv_file != $csv_confirm" if ($csv_file ne $csv_confirm);
+        } elsif ($app eq 'postfix/lmtp') {
+           if ($msg =~ /.* to=<([^>]*)>, .* Delivery OK\)$/) {
+               my $email = $1; 
+               $email =~ s/[^a-zA-Z0-9@\._-]//g;
+               system('/usr/local/sbin/notify.sh', $email);
+           }
+
         } else {
             next;
         }
Is there a better way of doing this?
Reply With Quote
  #3 (permalink)  
Old 11-08-2009, 12:46 PM
Junior Member
 
Posts: 5
Default

Quote:
Originally Posted by aratnaweera View Post
I managed to get this done by hacking zmlogger.
Unfortunately, the above didn't work out, as zmlogger is keeping an eye on /var/log/zimbra-stats.log and not zimbra.log.

The following script worked, although not the neatest way of doing it. This requires File::Tail (libfile-tail-perl on Ubuntu).

Code:
#!/usr/bin/perl

use strict;
use File::Tail;

my $log = File::Tail->new(name => '/var/log/zimbra.log', maxinterval => 2, interval => 1);
my $logregex = qr/^.{15} ((\d+\.\d+\.\d+\.\d+)|(\S+)) postfix\/lmtp\[\d+\]: .* to=<([^>]*)>, .* Delivery OK\)$/o;

while (defined(my $line = $log->read)) {
        chomp $line;
        if ($line =~ m/$logregex/) {
                my $email = $4;
                $email =~ s/[^a-zA-Z0-9@\._-]//g;
                system("/usr/local/bin/notify.sh '$email'");
        }
}
Reply With Quote
  #4 (permalink)  
Old 11-08-2009, 06:52 PM
Junior Member
 
Posts: 5
Default

Seems that this is the only way to get this done. Marking "solved".
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads

Why Join?

Registering let's you ask questions, makes it easier to search, displays any files attached to posts, and notifies you about replies.

blog.zimbra.com




 

SEO by vBSEO ©2011, Crawlability, Inc.