#!/usr/bin/perl use strict; use warnings; use Net::XMPP; use Mozilla::CA qw( ); my ($recipient, $message) = @ARGV; if(!($recipient) || !($message)) { print "Usage: $0 \n"; exit; } my $hostname = ''; my $sender = ''; my $password = '; my $connection = new Net::XMPP::Client(); print "Connecting to server. "; my $status = $connection->Connect( hostname => $hostname, connectiontype => 'tcpip', tls => 1, port => 5222, ssl_ca_path => Mozilla::CA::SSL_ca_file(), ); die("XMPP connection failed $!") if ! defined($status); print "Done!\n"; my @result = $connection->AuthSend( hostname => $hostname, username => $sender, password => $password); #die("XMPP authentication failed") if $result[0] ne 'ok'; if ($result[0] ne 'ok'){ print "XMPP authentication failed. Creating a new account\n"; print "Connecting again to server. "; my $status = $connection->Connect( hostname => $hostname, connectiontype => 'tcpip', register=>1, tls => 1, port => 5222, ssl_ca_path => Mozilla::CA::SSL_ca_file(), ); die("XMPP connection failed $!") if ! defined($status); print "Done!\n"; print "Trying to register new account. "; my @result = $connection->Execute( hostname=>$hostname, port=>5222, tls=>1, username=>$sender, password=>$password, #resource=>"new", register=>1, connectiontype=>'tcpip', #connecttimeout=>string, connectattempts=>2, connectsleep=>2, processtimeout=>3, ); } die("Creation account failed") if $result[0] ne 'ok'; my @messages = ('first message', 'second', 'third'); foreach (@messages){ die("XMPP message failed") if ($connection->MessageSend(to => $recipient, body => $_) != 0); sleep 3; } print "Message sent!\n"; #### There was an error in the last call to Process that you did not check for and handle. You should always check the output of the Process call. If it was undef then there was a fatal error that you need to check. There is an error in your program