Re: Strange problem with Mail::Send

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

From: Stas Bekman
Subject: Re: Strange problem with Mail::Send
Date: 01:23 on 19 Feb 2005
Ken Miller wrote:
> 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?

1) which mod_perl version are you using, Ken?

2) why do you use %ENV to pass the 'from' address, rather than pass it 
expicitly?

local() has the effect only for the block you defined it in, but if you've 
created a closure later on (not in %ENV at all), it may be the reason. 
just add debug prints to test it. I have a feeling that that's exactly 
what you are doing: creating a closure.

If you want us to look at it, please reduce the problematic code to the 
very minimum and post it here.


        -- 
        __________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@xxxxxx.xxx http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com

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