安装tlsmail
gem for email delivery to my gmail帐户后,每次运行rake命令时,这些错误都会出现:
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
如何摆脱这些警告?
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"
答案 0 :(得分:9)
如果您不想修改gem,请尝试:
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'
预加载net/smtp
和net/pop
gems并终止常量会阻止tlsmail
尝试加载和写入常量。这是一个肮脏,肮脏的黑客...但它的确有效!
(Ruby 1.9.2,tlsmail 0.0.1)
答案 1 :(得分:4)
至少,似乎你并不孤单。我对这个宝石并不十分熟悉,但看起来这可能是对你的修复:http://blog.snootymonkey.com/post/892799550/already-initialized-constant-warnings
默认情况下,ActionMailer(或其他一些邮件代码/插件)可能是Rails 3的一部分。请不要引用我,但这是我未经证实的预感,因为冲突的名称可能来自哪里
答案 2 :(得分:0)
tlsmail是ruby 1.9邮件向1.8的后端。所以你在ruby 1.9或更高版本中不需要tlsmail。
这个库在ruby 1.9和中动态替换net / smtp和net / pop 通过SSL / TLS启用pop或smtp。