I am using below code to connect to SMTP server where authentication is required for connection. While executing script I am getting an error message saying
"Error sending mail: Connection error from mail.utiba.com on port 465 ()". However the connection to the mail server is working fine, I can connect to the mail server using other mail clients.
Please suggest what I am doing wrong here. Is there any sendmail settings required?
#!/usr/bin/perl
use strict;
use warnings;
use Mail::Sendmail;
print "Testing Mail::Sendmail version $Mail::Sendmail::VERSION\n";
print "Default server: $Mail::Sendmail::mailcfg{smtp}->[0]\n";
print "Default sender: $Mail::Sendmail::mailcfg{from}\n";
my %mail = (
From=> 'username',
Bcc => '
[email protected]',
Cc=> '
[email protected]',
Subject => 'Test message',
'X-Mailer' => "Mail::Sendmail version $Mail::Sendmail::VERSION",
);
$mail{Smtp} = 'mail.server.com:port';
$mail{auth} = {user=>'username', password=>"password", required=>1 };
$mail{'X-custom'} = 'My custom additionnal header';
$mail{'mESSaGE : '} = "The message key looks terrible, but works.";
$mail{Date} = Mail::Sendmail::time_to_date( time() - 86400 );
if (sendmail %mail) {
print "Mail sent OK.\n" }
else {
print "Error sending mail: $Mail::Sendmail::error \n" }
print "\n\$Mail::Sendmail::log says:\n", $Mail::Sendmail::log;