Strange problem with Mail::Send

[prev] [thread] [next] [Date index for 2005/02/16]

From: Ken Miller
Subject: Strange problem with Mail::Send
Date: 20:58 on 16 Feb 2005
My web app sends notification emails when a task transitions from one 
part of the work flow to another.  I use Mail::Send to send mail, using 
a smtp server to transfer the mail.  The code looks something like this:

    my $mail = Mail::Send->new( Subject => 'a subject', To => 
'someone@xxxxxxx.xxx );
    my $fh = $mail->open( 'smtp', Server => 'some.host.name' );
    print $fh "A message\n";
    $fh->close;

To ensure that the recipient receives the mail from a recognizeable 
email address, I set the MAILADDRESS environment variable as follows:

    use constant FROM_ADDRESS => 'somebody@xxxxxxx.xxx';

and then, just before the above code to send the mail, I do this:

    local $ENV{ MAILADDRESS } = FROM_ADDRESS

This all works fine, except for one situation:

Ocassionally, the 'From' email address is not the constant address as 
shown above.  Instead, it's the 'from' email address from another part 
of the application completely unrelated to this notification email.  The 
code that sends this email uses this paradigm:

eval {
    local $ENV{ MAILADDRESS } = $some_other_email_address;
    (same mail boiler plate as above);
};

It almost seems that the mail address is getting stuck.

I don't have my mod-perl book handy right now, but I seem to remember 
that %ENV is restored after each request to the server startup state - 
is this correct?  If so, i should not need 'local' in front of the 
environment assignment, assuming that I'm not worries about the ENV 
changing during a request (which I'm not).

Is there some strange interplay going on between eval, local, and 
mod_perl that could cause this behaviour?  I've been unable to duplicate 
the problem in my test environment, so I'm just taking shots in the dark 
hoping to hit something.

Suggestions?

Cheers!

    -klm.

Strange problem with Mail::Send
Ken Miller 20:58 on 16 Feb 2005

Re: Strange problem with Mail::Send
Stas Bekman 01:23 on 19 Feb 2005

Generated at 11:21 on 20 Feb 2005 by mariachi v0.52