Thursday, May 5, 2011

Email to IM gateway, and other ways to send Instant Messages programmatically.

It's very easy to send an email programmatically. For example, in Perl you can do this:

open(MAIL, "|/usr/sbin/sendmail -oi -t") or die;
print MAIL "From: ...\n";
print MAIL "To: ...\n";
print MAIL "Subject: ...\n";
print MAIL "\n";
print Mail "... body ...";
close(MAIL);

I'd like to collect simple, self-contained snippets of code for programmatically sending an instant message (IM) in various languages (especially Perl) and for various protocols (especially jabber/gmail and AIM and Yahoo). See this question for a failed attempt in Perl for gchat: http://stackoverflow.com/questions/799648/error-using-perl-jabber

Or of course if there were an email-to-IM (instant message) gateway then sending an IM would be as easy as email. Perhaps no such thing exists but if anyone makes one, this would be a good place to point to it!

(Keywords to make this question more searchable: email, IM, instant messaging, jabber, xmpp, AIM, yahoo messenger, gmail, gchat, msn.)

PS: It's been over a year now and I suspect these answers are a little stale. Is there a better way to encourage updated answers besides re-asking the question?

From stackoverflow
  • You would need to have an account on the various IM networks, then find an API that can use the account and send messages on that network programmaticly.

    One multi-network library is libpurple (its used by the AdiumX and Pidgin IM clients), there appears to be a couple language bindings to the library:

    A quick search on Google gave me the impression of the availability of bindings for Python and Perl also.

  • Instant Messaging and Email are two different modalities, so you would need to have a custom gateway. This is how I would imagine it would work:

    1. You would create a bot using an API for a particular network: http://dev.aol.com/aim/bots for AOL.
    2. The bot would run as a service and be signed in and would receive emails.
    3. The bot would then create an Instant Messaging conversation with the target and send the message off.
    dreeves : Thanks; smart. I'm holding out hope that I can get something off the shelf to do this. Snippets of code for sending IMs in various protocols would also suffice for me.
  • I think your best bet is to take a look at an open source project and use their code! It saves you the trouble of having to code up each IM provider independently and you know you're getting a tested code base. Win Win!

    Take a look at pidgin it's an open source IM that supports AIM, Google Talk, IRC, MSN, ICQ, Yahoo! and others. And here's their source code information, I believe it is written in C, so you should have no problems interfacing it with Perl.

    dreeves : Has anyone used the libpurple code to make a command line utility to send IMs? That would solve my problem.
  • There is http://sendxmpp.platon.sk/ -- something like sendmail, but for xmpp. Then, from xmpp, you can set up transports for other IM networks.

    I guess this is the simplest method here. However if your program is more like a daemon, sendxmpp will be very slow -- and you'll benefit more from using a proper xmpp library.

  • Or of course if there were an email-to-IM (instant message) gateway then sending an IM would be as easy as email. Perhaps no such thing exists but if anyone makes one, this would be a good place to point to it!

    I'd turn this around - you don't need an email-to-IM gateway as much as you need an interface which sends 'a message' to 'an endpoint' where the endpoint would encode both the user's address and the means (possibly several, with fallbacks) of delivery. Thus, you'd be wrapping up several sending mechanisms (in Perl, pre-existing CPAN modules) with an interface that decides which mechanism to use. Thus all your snippets would end up brought together in a single CPAN module and other people would use it directly.

    While an email-to-IM gateway does solve the problem, who administrates it? If it's on the net somewhere, it's an independent point of failure (and one that sounds ripe for spam forwarding, so it wouldn't be around for long); if it's you, it's a separate component, and one that you'd probably find annoying when you got to the stage of testing your applications.

    dreeves : Excellent points; thanks! Love the meta-CPAN-module idea. Anyone?
    1. I know of a stealth mode startup working on an appliance that does exactly what you seek. It will sell in the $30K range.

    2. You will need an account for each of the IM networks.

    3. The appliance will have the additional capability of receiving IM replies and forwarding back via email.

    Unknown : Are you serious? Amazingly I have code to do this. If I can really sell it for $30k, I guess I should just keep it to myself instead of posting the answer here.
    dreeves : I'll give you 550 reputation points for it. :) I suppose I'd throw in some actual money too, but not thousands of dollars.
  • I know that ColdFusion's latest (and upcoming) version include a SMS Gateway for doing what you seek, but not in the languages that you are looking for. I'll see if I can find out more information for you and try to point you in the right direction. Cheers!

    Kevin Bomberry : Ah, I just remembered that I think I have a bit of code somewhere that has all of the telecom's SMS total length and email to SMS filters. Using this you can trim your message to the length, then send an email to the phone-number/email address and it gets delivered as an SMS (EX. 18005551212@mycinglarwireless.com). If you 'd like I can look for the file or find a posting for you on line and send you a link. Cheers!
    dreeves : As you noted, I was asking about IM rather than SMS. But that sounds extremely useful as well; I'd love to see that.
    Kevin Bomberry : @dreeves: Here's a short list for you: Carrier/Max-chars/email Alltel/300/10-digit-number@message.alltel.com AT&T Wireless/160/10-digit-number@mmode.com Boost Mobile/500/10-digit-number@myboostmobile.com Cingular/150/10-digit-number@mobile.mycingular.com OR 10-digit-number@cingularme.com Metrocall/80-200 depending on plan/10-digit-number@page.metrocall.com Nextel/140/10-digit-number@messaging.nextel.com Sprint PCS/160/10-digit-number@messaging.sprintpcs.com T-Mobile/140/10-digit-number@tmomail.net Verizon/160/10-digit-number@vtext.com Virgin Mobile USA/160/10-digit-number@vmobl.com
  • Here's CPAN modules for all the networks you requested.

    XMPP/Jabber/Google Talk:

    AOL Instant Messanger:

    MSN Messenger:

    Yahoo Messenger:

    dreeves : Thanks! This is the best answer so far. I had tried Jabber::SimpleSend to no avail. I'll try these.
    fiXedd : Thanks, I don't have a lot of experience with these, so I don't have a lot of code examples to offer. Hopefully their docs will prove useful.
  • I was going to add a comment onto fiXedd, but here's some actual sample Perl NET:AIM code from about 10 years ago.

    http://pedram.redhive.com/code/pedbot/

0 comments:

Post a Comment