Eman
Eman

Reputation: 6711

Perl script is not sending email

I am trying to send my first email (from a windows machine) with Perl, but I am getting an error:

SMTP Failed to connect to mail server: at emailer2.pl line 18 (msg->send;)

I am totally new to Perl so any help would be greatly appreciated. Has anyone encountered this problem before? I have searched for the error but I had no luck finding my exact problem.

Thanks so much for your help!

CODE:

#!/usr/bin/perl
use MIME::Lite;

$to = '[email protected]';
$cc = '[email protected]';
$from = '[email protected]';
$subject = 'Test Email';
$message = 'This is test email sent by Perl Script';

$msg = MIME::Lite->new(
                 From     => $from,
                 To       => $to,
                 Cc       => $cc,
                 Subject  => $subject,
                 Data     => $message
                 );

$msg->send;
print "Email Sent Successfully\n";

Upvotes: 0

Views: 875

Answers (2)

Jose Rey
Jose Rey

Reputation: 251

You may also use another mail server setting default parameters before sending the message

MIME::Lite->send('smtp', "smpt.example.org", Timeout=>60, SSL=>1,
                 AuthUser=>"myself", AuthPass=>"mysecret");

Take a look at MIME::Lite sending section.

Upvotes: 0

elixenide
elixenide

Reputation: 44823

It means you don't have a mail server running on your machine. You need to install one and make sure it is running.

Upvotes: 2

Related Questions