#!/usr/bin/env perl use strict; use warnings; use feature 'say'; use AnyEvent::XMPP::IM::Connection; use AnyEvent::XMPP::IM::Message; use Getopt::Long; my $from_stdin = 0; my $from_file = 0; GetOptions( input => \$from_stdin, 'file=s' => \$from_file, ); my $body; if($from_stdin || $from_file) { my $fh; if($from_stdin) { $fh = \*STDIN; } else { open $fh, '<', $from_file or die "Unable to open $from_file: $!\n"; } $body = do { local $/; <$fh>; }; close $fh; } elsif(@ARGV) { $body = join(' ', @ARGV); } else { die "usage: $0 [-i] [-f file] [message...]\n"; } my $cond = AnyEvent->condvar; my $conn = AnyEvent::XMPP::IM::Connection->new( jid => 'your source JID here', password => 'your password here', domain => 'gmail.com', # I use Google Talk for this; you can # remove the domain, host, port, and # old_style_ssl options if you use # a "regular" XMPP server host => 'talk.google.com', port => 5223, old_style_ssl => 1, initial_presence => undef, ); my $timer; $conn->reg_cb(session_ready => sub { my $msg = AnyEvent::XMPP::IM::Message->new( to => 'your destination JID here', type => 'chat', body => $body, ); $msg->send($conn); $timer = AnyEvent->timer( after => 3, cb => sub { $cond->send }, ); }); $conn->reg_cb(error => sub { my ( undef, $error ) = @_; say $error->string; $cond->send; }); $conn->connect; $cond->recv;