Running scripts in rails

Hi there.
I’ve got a Rails 2.2.2 app running with a monkey patch, (for
enable/disable tls in actionmailer) this patch executes perfectly, but
not in scripts in production ENV

This is the monkey patch in environment.rb:
http://pastebin.com/m699a8fc5

And this is the script that I’m running: http://pastebin.com/m4cdba602

the script is located in script directory, and I execute it like this:
[./script/teste_email] development env
[RAILS_ENV=production ./script/teste_email] production env

In development env the scripts works fine, and also the patch, but in
production env the patch is not being loaded.
So I’ve got the error messages that the patch is suposed to fix:
“/usr/lib/ruby/1.8/openssl/ssl.rb:123:in `post_connection_check’:
hostname was not match with the server certificate
(OpenSSL::SSL::SSLError)”

Does anyone have some experience in this kind of problem?

…solved with
RAILS_ENV=production script/runner myscript.rb