I am writing a script to test a handful of mail accounts on our mailserver. This script needs to run automatically every half hour on a Windows machine, unfortunately, I don't have access to cron. My questions are: Is the script below the way to do this? and; Can anyone recommend a better method?
#!/usr/bin/perl -w
use strict;
use MIME::Lite;
use Date::Calc qw(Today_and_Now
Date_to_Text_Long);
my $gmt;
my $sleeptimer;
my ($year,$month,$day, $hour,$min,$sec) = Today_and_Now([$gmt]);
my $sig = "\n\nHere is my sig";
my $time = sprintf("%s, %s:%s:%s",
Date_to_Text_Long($year,$month,$day),
$hour,
$min,
$sec
);
my $msg = MIME::Lite->new(
From =>'test@account.com',
To =>'test1@account.com',
Cc =>'test2@account.com, test3@account.com',
Bcc =>'test@account.com',
Subject =>'This is a test message',
Data =>"This message was sent from my script:\n\n
+$time$sig"
);
if ($min > 30) {
$sleeptimer = 60 - $min;
$sleeptimer = $sleeptimer * 60;
} elsif ($min < 30) {
$sleeptimer = 30 - $min;
$sleeptimer = $sleeptimer * 60;
} else {
$sleeptimer = 1800;
}
if ($sleeptimer ne 1800) {
sleep $sleeptimer;
}
do {$msg-> send('smtp', "mail.server.com", Timeout=>60);
sleep 1800;
redo;
}
Edited: Retitled