from from esx console command line using perl

from from esx console command line using perl

#!/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

Leave a Reply

Your email address will not be published. Required fields are marked *

3 × four =

This site uses Akismet to reduce spam. Learn how your comment data is processed.