Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

warning: already initialized constant after installing tlsmail gem?

After I installed the tlsmail gem for email delivery to my gmail account, these erros keep coming up every time I run a rake command:

c:/Ruby192/lib/ruby/gems/1.9.1/gems/tlsmail-0.0.1/lib/net/smtp.rb:806: warning: already initialized constant SMTPSession
c:/Ruby192/lib/ruby/gems/1.9.1/gems/tlsmail-0.0.1/lib/net/pop.rb:687: warning: already initialized constant POP
c:/Ruby192/lib/ruby/gems/1.9.1/gems/tlsmail-0.0.1/lib/net/pop.rb:688: warning: already initialized constant POPSession
c:/Ruby192/lib/ruby/gems/1.9.1/gems/tlsmail-0.0.1/lib/net/pop.rb:689: warning: already initialized constant POP3Session
c:/Ruby192/lib/ruby/gems/1.9.1/gems/tlsmail-0.0.1/lib/net/pop.rb:702: warning: already initialized constant APOPSession

How can I get rid of these warnings?


gem 'rails', '3.0.10'
gem "rake", "0.8.7"
gem "pg", "0.12.0"
gem "cancan", "1.6.7"
gem "geocoder", "1.0.5"
gem "will_paginate", "3.0.2"
gem "rails3-jquery-autocomplete"
gem "jquery-rails", "1.0.19"
gem "dynamic_form", "1.1.4"
gem "devise", "1.5.3"
gem "thin", "1.3.1"
gem 'sunspot_rails', '1.2.1'
gem "tlsmail"
like image 685
LearningRoR Avatar asked Dec 01 '25 08:12

LearningRoR


2 Answers

If you don't want to modify the gem, try this:

require 'net/smtp'
Net.instance_eval {remove_const :SMTPSession} if defined?(Net::SMTPSession)

require 'net/pop'
Net::POP.instance_eval {remove_const :Revision} if defined?(Net::POP::Revision)
Net.instance_eval {remove_const :POP} if defined?(Net::POP)
Net.instance_eval {remove_const :POPSession} if defined?(Net::POPSession)
Net.instance_eval {remove_const :POP3Session} if defined?(Net::POP3Session)
Net.instance_eval {remove_const :APOPSession} if defined?(Net::APOPSession)

require 'tlsmail'

Preloading the net/smtp and net/pop gems and killing the constants prevents tlsmail from trying to load and write over the constants. It's a filthy, filthy hack ... but it works!

(Ruby 1.9.2, tlsmail 0.0.1)

like image 181
peat Avatar answered Dec 04 '25 00:12

peat


At least, it seems, that you're not alone. I'm not terribly familiar with that gem, but it looks like this might be a fix for you: http://blog.snootymonkey.com/post/892799550/already-initialized-constant-warnings

It's possible that ActionMailer (or some other mailer code/plugin) is included by default as part of Rails 3. Don't quote me on that, but that's my unsubstantiated hunch as far as where the conflicting names might be coming from.

like image 35
jefflunt Avatar answered Dec 03 '25 22:12

jefflunt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!