APLawrence.com -  Resources for Unix and Linux Systems, Bloggers and the self-employed
RSS Feeds RSS Feeds











(OLDER) <- More Stuff -> (NEWER) (NEWEST)
Printer Friendly Version


Sending Kerio Calendar Event Reminders by Email

One of the things I really wish Kerio® would add to their Calendaring is the ability to send email reminders rather than just pop-ups. This has annoyed me for some time and while I hoped to see it in the upcoming Connect 8.0 release, it's not in there, so I wrote a server-side script to do the job.

The script is rough; I haven't expended a lot of effort on it. It does work, at least for the cases I tested. As usual, you need to be sure that it works for you before depending upon it.

Some notes:

This depends upon the "Reminder" box being checked. It only sends email when a reminder pop-up is scheduled.

Recurring events won't be seen after the first unless the pop-up is acknowledged. You could write more complicated code that didn't depend on that, but this isn't it. I think that eventually the pop-up might self-acknowledge, but I haven't tested that. It would make sense for it to do that, but I'm not sure about that.

As this will send email BEFORE the scheduled pop-up reminder, it makes sense to have it run frequently. On the other hand, if it has a lot to do, it could miss events if you run it too frequently. Again, more complicated code could deal with that but I didn't bother.


#!/usr/bin/perl
use Date::Manip;
# You could do this without Date::Manip, but it's more work.
#
$STORE="/opt/kerio/mailserver/store";
@DOMAINS=("aplawrence.com","foobar.com");
# Set these to match your system
#
$PERIOD=60 * 5; # 5 minute loop, change to whatever you like
# However, if it runs too often and there are many events to process,
# it can miss events.
$DEBUG=1; # set to 0 for normal operation
#
while (1) {
foreach(@DOMAINS) {
  $domain=$_;
  chdir("$STORE/mail/$domain");
  foreach(<*>) {
   # you could exclude users with 
   # next if /^sam$/;
   # next if /^bill/;
   # or just do a few selected:
   # next if (not /^tony$/ and not /^linda/);
   #
   $user=$_;
   chdir("$STORE/mail/$domain/$user/Calendar/#msgs") or next;   
   foreach(<*.eml>) {
     $message=$_;
     open(CAL,$message);
     @cal=<CAL>;close CAL;
     $alarm="";
     @attend="";$summary="";$organizer="";
     foreach(@cal) {
       $summary=$_ if /Summary:/i;
       $reminder=$_ if /TRIGGER.*PT/;
       $summary=~ s/.*://;
       push @attend,$_ if /ATTENDEE/;
       $organizer=$_ if /ORGANIZER/;
       $organizer=~ s/.*://;
       $alarm=$_ if /NEXT-ALARM/;
       }
       $reminder=~s/.*PT//;
     if ($alarm) {
       $alarm=~ s/.*://;
       $atime=UnixDate(ParseDate($alarm),"%s");
       $nowtime= $atime - time();
         # this next section might use some work - good enough for my use
         $reminder=~s/.*PT://;
         $multiplier=60 if $reminder=~ /M/;
         $multiplier=60 * 60  if $reminder=~ /H/;
         $multiplier=60 * 60 *24  if $reminder=~ /D/;
         $reminder=~ s/[D-M].*//;
         $reminder *= $multiplier;
         $starts_at=$atime + $reminder;
         #
       if ($DEBUG and ($nowtime > 0)) {
         print "\nChecking $user/Calendar/#msgs/$message\n";
         print "remaining $nowtime seconds for $summary" ;
         print "Starts at ", scalar localtime($starts_at),"\n";
       }
      if ($nowtime <= $PERIOD and $nowtime > 0) {
      # Note that the email is sent sometime BEFORE the reminder fires off
      # If you hate that, you'd need to spawn off another process
      # that would wait until the precise time.  It wasn't important
      # for me.
      #
       print "$summary $start $organizer ", scalar localtime($starts_at),"\n" if ($DEBUG);;
       open(SEND,"|/opt/kerio/mailserver/sendmail $organizer"); 
       print SEND "Mime-Version: 1.0\n";
       print SEND "Content-Type: text/html\n";
       print SEND "Content-Transfer-Encoding: 8BIT\n";
       print SEND "Subject: Reminder $summary\n";
       print SEND "\n$summary starts at ",scalar localtime($starts_at),"\n";
      # I'm just listing attendees here, but it wouldn't be hard 
      # to send each of them a reminder also.  
      #
       foreach(@attend) {
         print if $DEBUG;
         print SEND;
       }
       close SEND;
       print "\n\n" if $DEBUG;
     }
      
     }
   }
   }

  }
print "sleeping  $PERIOD\n" if $DEBUG;;
sleep $PERIOD;
}
 

By the way, one use for this would be to get calendar reminders sent by SMS. To do that, you'd define a user rule that identified these types of messages (Subject contains Reminder, perhaps) and forwarded them to your SMS mail gateway number (see SMS through E-Mail).


Kerio®, and related trademarks, names and logos are the property of Kerio Technologies, Inc. and are registered and/or used in the U.S. and other countries. Used under license from Kerio Technologies, Inc.


If this page was useful to you, please help others find it:  





4 comments




More Articles by Anthony Lawrence - Find me on Google+



Click here to add your comments





Sat Sep 15 06:52:35 2012: 11315   anonymous

gravatar


Connect 8.0 ?! The "next major version" which wil drop BES support ?
For those of us that aren't part of the developer program, would you by any chance have an ETA for Connect 8.x ?



Sat Sep 15 11:39:46 2012: 11317   TonyLawrence

gravatar


I don't know, but as we're seeing Knowledge Base articles that reference it, it can't be too far away.



Sat Sep 15 12:01:02 2012: 11318   TonyLawrence

gravatar


Fixed a bug - $start_at was only set if $DEBUG was.. corrected above.

Probably more bugs to come..



Sun Sep 16 13:51:39 2012: 11323   TonyLawrence

gravatar


As written here, this won't send the email on recurring events if popups events are not acknowledged.

It CAN be rewritten to fix that - I'll get around to it eventually.

Don't miss responses! Subscribe to Comments by RSS or by Email

Click here to add your comments


If you want a picture to show with your comment, go get a Gravatar



LOD Communications, Inc.
Kerio Connect Recovery

Kerio Connect Mailserver

Kerio Control Firewall

Have you tried Searching this site?

Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more. We appreciate comments and article submissions.

Publishing your articles here

Jump to Comments



Many of the products and books I review are things I purchased for my own use. Some were given to me specifically for the purpose of reviewing them. I resell or can earn commissions from the sale of some of these items. Links within these pages may be affiliate links that pay me for referring you to them. That's mostly insignificant amounts of money; whenever it is not I have made my relationship plain. I also may own stock in companies mentioned here. If you have any question, please do feel free to contact me.

Specific links that take you to pages that allow you to purchase the item I reviewed are very likely to pay me a commission. Many of the books I review were given to me by the publishers specifically for the purpose of writing a review. These gifts and referral fees do not affect my opinions; I often give bad reviews anyway.

We use Google third-party advertising companies to serve ads when you visit our website. These companies may use information (not including your name, address, email address, or telephone number) about your visits to this and other websites in order to provide advertisements about goods and services of interest to you. If you would like more information about this practice and to know your choices about not having this information used by these companies, click here.

pavatar.jpg

This post tagged:

       - Kerio
       - Kerio Info
       - Kerio Pricing
       - Kerio RSS Feed
       - Mail
       - Perl
       - Scripting


















My Troubleshooting E-Book will show you how to solve tough problems on Linux and Unix systems!


book graphic unix and linux troubleshooting guide



Buy Kerio from a dealer
who knows tech:
I sell and support

Kerio Connect Mail server, Control, Workspace and Operator licenses and subscription renewals