简体   繁体   中英

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 = 'myemail@gmail.com';
$cc = 'myemail@gmail.com';
$from = 'myemail@gmail.com';
$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";

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

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM