Hello:

I am creating an automated Mail Manager called automailer.pl that use MySQL and perl modules. I am using MIME:: Lite, Net::SMTP and of course, DBI. The script will run fine for about 40 or 50 emails, but eventually, I will get this crazy error and hte script will fail:

Exception caught: Failed to connect to mail server: Bad file descriptor at automailer.pl line 219

Could not commicate with "mailserver". Connection refused at automailer.pl line 182, <STDIN> line 3.

The code that sends the emails is here:

#### Subroutine for sending email message: #### Subroutine for sending email message: sub mailfunc { my($to, $from, $subject, @body) = @_; use MIME::Lite; use Net::SMTP; my $relay = "gorillatrades.com"; ## Mail Server. my $smtp = Net::SMTP->new($relay); ## Mail Object Handler. die "Could not commicate with $relay. $!" if (!defined $smtp); my @images; ## Stores Images references; my $message = join(' ', @body),"\n"; # Create the initial text of the message my $mime_msg = MIME::Lite->new( From => $from, To => $to, Subject => $subject, Type => "multipart/mixed", ) or die "Error creating MIME body: $!\n"; ##Find all image references ##Converting MIME type into String: #print "$message"; #HTML $mime_msg-> attach(Type => 'text/html', Data => "$message"); my $message_body = $mime_msg-> body_as_string(); #### Send out Email. ## Second Send Message Using ONLY MIME MIME::Lite->send('smtp', $mailserver, Timeout=>60); eval { $mime_msg-> send(); }; $@ and warn "Exception caught: $@\n\n"; print "Sent Normally to $to.\n\n"; $@ and warn "Exception caught: $@\n\n"; }

The failure happens sporadically. It will work fine for 200 emails and then the next day it will fail on 20.
Is there some bug in MIME or Net that I don't know about? could there be something else going on?

- Cappa

Janitored by holli - added code tags


In reply to MIME Lite Module constantly crashing by Cappadonna3030

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.