Search code examples
perlemailsmtpsendfile-descriptor

Perl MIME::Lite bad file descriptor


This is my code so far:

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

my $to = 'example@asd.com';
my $from = 'example@asd.com';
my $subject = 'Test Email';
my $message = 'This is test email sent by Perl Script';

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

$msg->add( "Type" => "multipart/mixed" );        
$msg->send("smtp", "good.domain.net");
print "Email Sent Successfully\n";

When i want to run the script i got the following error:

Failed to connect to mail server: Bad file descriptor at ...\email.pl line 17.

I have no idea what the problem could be. Has someone any idea how to fix this?

EDIT: I corrected the code above, it is working with the proper server (it does not require authentication at all).


Solution

  • MIME::Lite SMTP debugging procedure

    Try to narrow search for your problem.

    1: Do you get SMTP greeting message when you telnet the SMTP host?
    telnet mail.domain.net 25

    1:YES => add debug option to MIME::Lite send (via SMTP) call.

    $msg->send("smtp", "mail.domain.net", Debug=>1, AuthUser=>'myname@domain.com', AuthPass=>"password" );