from from esx console command line using perl
- Angelo Schalley
- Dec, 16, 2010
- Linux, vmware
- No Comments
#!/usr/bin/perl -w
use Net::SMTP;
my $smtpServer = 'smtpserver.company.com';
my $mailFrom = 'sender@companyname.com';
my $mailTo = 'recipient@companyname.com';
my $subject = 'Test Mail';
my $emailFile = '/usr/local/bin/report.txt';
sendmail($smtpServer,$mailFrom,$mailTo,$subject,$emailFile);
sub sendmail {
my $smtpserver = $_[0];
my $sender = $_[1];
my $recipient = $_[2];
my $subject = $_[3];
my $filename = $_[4];
`/usr/sbin/esxcfg-firewall -o 25,tcp,out,SMTP`;
my $smtp = Net::SMTP->new($smtpserver);
$smtp->mail($sender);
$smtp->to($recipient);
$smtp->data();
$smtp->datasend("Subject: $subject\n");
$smtp->datasend("To: $recipient\n");
$smtp->datasend("\n");
open (MESSAGE, $filename);
my @body=
close MESSAGE;
foreach my $line (@body) {
$smtp->datasend("$line");
}
$smtp->dataend();
$smtp->quit;
`/usr/sbin/esxcfg-firewall -c 25,tcp,out,SMTP`;
}
save as script.pl
check if you firewall is passing port 25 to your mailserver
“service firewall status” from command line