rhubarbpie has asked for the wisdom of the Perl Monks concerning the following question:

I receive "Bad file descriptor" when send mail to Gmail using MIME::Lite. Assuming I'm bob with a 123456 password, what's wrong with the following code? I am able to successfully send mail using Email::Send::Gmail and Email::Simple::Creator. However, I'd like to send attachments and html format.
use strict; use warnings; use MIME::Lite; my $msg = MIME::Lite->new( From =>'bob@gmail.com', To =>'bob@gmail.com', Subject =>'test' ); MIME::Lite->send('smtp', 'smtp.googlemail.com', Port=>'465', Timeout=> + 60, Debug=>1, AuthUser=>'bob', AuthPass=>'123456'); $msg->send();
The output and error are as follows:
MIME::Lite::SMTP>>> MIME::Lite::SMTP MIME::Lite::SMTP>>> Net::SMTP(2.29) MIME::Lite::SMTP>>> Net::Cmd(2.26) MIME::Lite::SMTP>>> Exporter(5.58) MIME::Lite::SMTP>>> IO::Socket::INET(1.29) MIME::Lite::SMTP>>> IO::Socket(1.29) MIME::Lite::SMTP>>> IO::Handle(1.25) MIME::Lite::SMTP=GLOB(0x840770c): Timeout at /usr/lib/perl5/site_perl/ +5.8.8/MIME/Lite.pm line 2865 SMTP Failed to connect to mail server: Bad file descriptor at Monks.prl line 14

Replies are listed 'Best First'.
Re: Bad file descriptor with mail to Gmail using MIME::Lite.
by Anonyrnous Monk (Hermit) on Jan 13, 2011 at 00:29 UTC

    I think Email::Send::Gmail is using Net::SMTP::SSL under the hood to connect to googlemail, whereas MIME::Lite is using plain (non-SSL) Net::SMTP.

    Simply specifying the SSL SMTP port 465 with MIME::Lite isn't going to help, as (I suppose) googlemail expects to communicate via secured protocol, which MIME::Lite currently doesn't do...

    (A couple of month ago, there was a thread about patching MIME::Lite to also support SSL/TLS on port 465/587 — but I'm not sure what to make of it :)

    Update: it's probably easier to construct the (multipart) email using Email::MIME (instead of Email::Simple) and then send it with Email::Send::Gmail.

      Thank you for the suggestion. I'd thought of that and tried the following:
      use strict; use warnings; use Email::Send; use Email::Send::Gmail; use MIME::Lite; my $msg = MIME::Lite->new( From =>'bob@gmail.com', To =>'bob@gmail.com', Subject =>'test' ); my $sender = Email::Send->new( { mailer => 'Gmail', mailer_args=>[ username=>'bob@gmail.com',password=>'123456',] } ); eval { $sender->send($msg) }; die "Error sending email: $@" if $@;
      I receive no error, but the code immediately returns to a prompt and no mail is sent. I am somewhat new to this and assume you suggested I patch the "send" part (which works with Email::Simple::Creator) to my existing MIME code. Correct? Thoughts?
        ... Correct?

        Yes and no :)

        What I was thinking of was to replace Email::Simple::Creator with Email::MIME::Creator to create the msg, as the latter module is essentially the "multipart" extension of the former... from the same author, so chances are good that if Email::Simple::Creator works, the MIME variant might work, too.

Re: Bad file descriptor with mail to Gmail using MIME::Lite.
by zentara (Cardinal) on Jan 13, 2011 at 15:23 UTC
      I thank everyone for replying. I'd like to report my solution in hopes of helping the next guy with difficulty mailing to Gmail. Email::Send::SMTP::Gmail works well for me, including attachments. There may well be other solutions, but it seems quite simple and works well. Again, assuming I'm "bob" with a "123456" password, the following code works:
      use strict; use warnings; use Email::Send::SMTP::Gmail; my $mail=Email::Send::SMTP::Gmail->new( -smtp=>'gmail.com', -login=>'bob', -pass=>'123456'); $mail->send(-to=>'bob@gmail.com', -subject=>'Mail w/attachment test', -verbose=>'1', -body=>'Test', -attachments=>'file.zip'); $mail->bye;