Here is all soubroutines which I write to my script.
use Net::SMTP;
$from = "SMSrobot";
$to = "me\@mydomai.com";
$smtp_retry = "3";
$smtp_timeout = "60";
$smtp_server = "smtp.provider.com";
# --------------------------------------------------------------------
+-----
#sub smtp
sub smtp {
my ( $message ) = @_[0];
&logging("Conecting to $smtp_server SMTP server...");
unless ( $smtp = Net::SMTP->new( $smtp_server, Hello => $from, Tim
+eout => $smtp_timeout ) ) {
&logging("Can't connect.");
return 0;
}
&logging("Conected.");
unless ( $smtp->mail( $from ) and $smtp->to( $to ) ) {
&logging("Can't initialize communication");
return 0;
}
&logging("Sending mail to $to");
unless ( $smtp->data() and $smtp->datasend("$message\n") and $smtp
+->dataend() and $smtp->quit) {
&logging("Can't send data.");
return 0;
}
$message =~ s/\s/ /isg;
&logging("Message: \"$message\" was sent.");
&logging("Quit.");
return 1;
}
Just call this by &smtp('mail message'); |