Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Mime::Lite Sendmail Dying

by halfbaked (Sexton)
on Nov 22, 2013 at 04:29 UTC ( [id://1063866]=perlquestion: print w/replies, xml ) Need Help??

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

I'm using Mime::Lite in a Perl module that I'm running as a daemon via an init.d script. It was running fine until I upgraded Debian from squeeze to wheezy. Now I get this message when it finds an email message in my database to send.
2013-11-21 23:10:37 [MIME::Lite 13557] : **** DIE!!! **** error closin +g /usr/lib/sendmail: No child processes (exit -1) Additionally, an error occurred sending the alert email: error closin +g /usr/lib/sendmail: No child processes (exit -1) 2013-11-21 23:10:37 [Proc::PID::File 13557] : **** Permission denied a +t /usr/local/share/perl/5.14.2/Proc/PID/File.pm line 224 during globa +l destruction.
Here's the relevant code.
while (my $row = $get_sth->fetchrow_hashref) { if ($row->{messagetext} && $row->{messagehtml}) { if ($debug == 1) { $row->{recipient} = 'webdev@naplesrentals.com'; $msgcnt++; } my $status = 'sent'; my $message = new MIME::Lite( To => $row->{recipient}, From => $row->{sender}, Subject => $row->{subject}, Type => 'multipart/alternative'); $message->attach(Type=>'text/plain', Data=>$row->{messagetext}); $message->attach(Type=>'text/html', Data=>$row->{messagehtml}); $upd_sth->execute($status, $row->{messageid}); $message->send_by_sendmail or logmsg('Warning'); logmsg("Delivered message: MessageID: " . $row->{messa +geid}); } else { $upd_sth->execute('error', $row->{messageid}); logmsg("Invalid message: MessageID: " . $row->{message +id} . " Next!"); } }
And here's the code the starts the process.
sub start { my $self = shift; my $name = $self->name; if (my $pid = fork()) { # parent + + exit 0; } #Child + + if (Proc::PID::File->running({name=>$name})) { die "Couldn't start: '$name' already running."; } $self->init_mailer_daemon; }
The init_mailer_daemon function ...
sub init_mailer_daemon { my $self = shift; my $name = $self->name; print "Starting: '$name'\n"; *CORE::GLOBAL::warn = \&warn_to_log; $SIG{__DIE__} = \&die_to_log; $SIG{__WARN__} = \&warn_to_log; eval { chdir '/' or die $!; open STDIN, '/dev/null' or die $!; open(STDOUT, '>>' . $self->logfile); open(STDERR, '+>&STDOUT'); logmsg('Starting Listmanager'); POSIX::setsid or die $!; logmsg('Successful'); }; if ($@) { die "Couldn't start child '$name': $@"; } local $SIG{CHLD} = 'IGNORE'; &queue; }

Replies are listed 'Best First'.
Re: Mime::Lite Sendmail Dying
by Corion (Patriarch) on Nov 22, 2013 at 07:38 UTC

    The error message sounds to me as if /usr/bin/sendmail either does not exist, or cannot be launched by your daemon, or exits prematurely for whatever reason.

    Does the mail sending code work when run outside of your daemon? If it works, then the problem is likely a permissions issue.

    If the mail sending code still fails outside of your daemon, consider looking at the debug output, which can be enabled through

    Debug => 1

    in the constructor.

      The email message does get sent but deamon dies.

        You still don't tell us what happens when you run your mail sending code outside of your daemon.

        Searching the MIME::Lite code for the error message brings me to this snippet:

        } else { ### parent $self->print( \*SENDMAIL ); close SENDMAIL || die "error closing $p{Sendmail}: $! (exi +t $?)\n"; $return = 1; }

        ... which indicates that one workaround could be to use a method other than sendmail. For example, you could attempt direct delivery. But with that, you forego all the niceties of using an MTA, like retries, bounces etc.

        Another approach could be to simply paper over the problem by using eval:

        my $sent_ok= eval { $mail->send; 1; }; if( my $err= $@ ) { warn "Error while sending mail: '$err'"; };

        That way, your daemon will survive. Still, it remains unclear why sendmail would change behaviour in the way it appears.

Re: Mime::Lite Sendmail Dying
by kcott (Archbishop) on Nov 22, 2013 at 06:17 UTC

    G'day halfbaked,

    I suggest you take a look at the opening caveat in the MIME::Lite documentation:

    WAIT!
    MIME::Lite is not recommended by its current maintainer. There are a number of alternatives, like Email::MIME or MIME::Entity and Email::Sender, which you should probably use instead. MIME::Lite continues to accrue weird bug reports, and it is not receiving a large amount of refactoring due to the availability of better alternatives. Please consider using something else.

    -- Ken

      I find this part of the documentation highly misleading. At least in my experience, MIME::Lite works quite well. But I mostly use it on Windows and Debian, so maybe other OSes/distributions are more problematic.

        Neither were any problems on CentOS 5, 6, and FreeBSD 8 (possibly earlier ones too) with the module itself.
      Hmm, I wrote this thing years ago, so you might be on to something, perhaps it makes the most sense to move on to another module.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1063866]
Approved by kcott
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2024-04-24 22:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found