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 => '[EMAIL PROTECTED] );
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 => '[EMAIL PROTECTED]';

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.



Reply via email to