Coherent Blahs

Email filter to Google Talk message

by Indiangeek on Nov.27, 2009, under Linux, Technology, Tips n Tricks

Not all Emails are made equal. And some have the priority that they cannot wait.  Given that, I was looking for a way to filter out mails, and get a quick notification on some high priority Emails.
Since I have an Android phone, the best way for me to get notified is either through SMS, or through Google Talk. SMS costs money. So, I wanted the notification to come over GTalk.
My work Email resides on an Exchange server, and it has no way to filter an Email and generate a GTalk notification from it. So, I had to look for some client side solution.
Looking around the web, I found GTalk uses jabber as the underlying protocol, and I can use xmpp libraries to communicate with it.

So I coded up a small, ugly, hardcoded Perl script to get the job done.

 1 #!/usr/bin/perl
 2 use Net::XMPP;

 3
 4 my $username = 'uuuuuuuu';
 5 my $password = 'pppppppp';

 6
 7 my $resource = 'MailToTalk';
 8 my $hostname = 'talk.google.com';

 9 my $port = 5222;
10 my $componentname = 'gmail.com';

11 my $connectiontype = 'tcpip';
12 my $tls = 1;
13 my $msg = $ARGV[0];

14
15 # Connect to Google Talk
16 my $Client = new Net::XMPP::Client();

17 $Client->Connect(   hostname => $hostname,
18                     port => $port,

19                     componentname => $componentname,
20                     connectiontype => $connectiontype,
21                     tls => $tls );

22 my $sid = $Client->{SESSION}{id};
23 $Client->{STREAM}->{SIDS}->{$sid}->{hostname} = $componentname;

24 $Client->AuthSend(  username => $username,
25                     password => $password,

26                     resource => $resource );
27
28 print "Sending $msg";

29 my $ret = $Client->MessageSend(
30                         to =>"$username\@gmail.com", body=> $msg,

31                         resource => $resource);
32 $Client->Disconnect();
33 exit();

Replace uuuuuuuu with your Google username and pppppppp with your Google password. The Perl script takes a string as input, and sends it to the user’s Google Talk account as an instant message. You must have Perl Net-XMPP installed in your system.

Once you have tested the script, it can be hooked up to a Mail client filter. The key here is, your mail client should be able to execute a native program as part of the filtering action.

I use KMail as my primary mail client, and it does have a way to do this:

KMail Filter Configuration

KMail Filter Configuration

I’ve used this feature on Evolution Mail, but haven’t seen it on Mozilla Thunderbird.

With these two hooked up, it’s possible to get a Google Talk notification whenever that important Email arrives.

Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Google
:, , ,

Leave a Reply

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...