package MtelMailer;
# $Id: MtelMailer.pm,v 1.2 2004/09/06 21:22:15 weby Exp $
# Author: Vulcho Nedelchev <kumcho@vulcho.com>
# Object oriented wrapper to send sms via bulgarian GSM operator
use Carp;
use Net::SMTP;
use strict;
sub new{
my $class = shift;
my $this = {@_};
for (qw(to from sms)){
confess "Missing {$_}" unless exists $this->{$_};
}
$this->{host} = "smsgw.mtel.net";
$this->{timeout} = 10;
$this->{verbose} = 1;
bless $this, $class;
return $this;
}
sub connect{
my $this = shift;
unless (ref $this){
croak "Sould call connect() whitin a classn\n";
}
$this->{smtp} = Net::SMTP->new( $this->{host},
Timeout => $this->{timeout});
confess "Cannot connect to mail server: $!" unless $this->{smtp};
if ($this->{verbose}){
print "Connected to SMTP server: ", $this->{smtp}->domain,"\n";
}
}
sub disconnect{
my $this = shift;
if ($this->{verbose}){
print "Closing connection to server ", $this->{smtp}->domain, "\n";
}
if (defined($this->{smtp})){
$this->{smtp}->quit;
}
}
sub send{
my $this = shift;
if ($this->{verbose}){
print "Sending message to ", $this->{to}, "\n";
}
$this->connect();
$this->{smtp}->mail($this->{from});
$this->{smtp}->to($this->{to});
$this->{smtp}->data;
$this->{smtp}->datasend("To: ".$this->{to}."\r\n");
$this->{smtp}->datasend("From: ".$this->{from}."\r\n");
$this->{smtp}->datasend("\r\n");
$this->{smtp}->datasend($this->{sms});
$this->{smtp}->dataend;
$this->disconnect();
return;
}
1;
__END__
=cut
=head1 NAME
This module name is MtelMailer.pm
=head1 SYNOPSIS
use MtelMailer;
my $sms = new MtelMailer(sms => "Text to send to client",
from => "You <user\@host.org>",
to => "35988XXXXXXX\@sms.mtel.net",
verbose => 1);
$sms->send();
=head1 DESCRIPTION
This is OO way and easy way to send SMS to bulgarian GSM operator MTEL.
=head1 AUTHOR
Vulcho Nedelchev <kumcho@vulcho.com>
=head1 BUGS
If You find a bug - fix it :-)
=cut