2011-09-17 22 views
0

我使用巫術來激活電子郵件,並且我遵循他們的wiki教程:https://github.com/NoamB/sorcery/wiki/User-Activation。 我很確定問題在於發送電子郵件,而不是如此激活,因爲這是另一個問題。當我嘗試通過Sorcery使用激活時,爲什麼Rails 3 Action Mailer不會發送電子郵件?

下面是用戶梅勒代碼:

class UserMailer < ActionMailer::Base 
    default :from => "[email protected]" 

    def activation_needed_email(user) 
    @user = user 
    @url = "http://0.0.0.0:3000/users/#{user.activation_token}/activate" 

    mail :to => user.email, 
     :subject => "Welcome to PolyHerd.com" 
    end 
end 

這是我的development.rb文件:

SampleApp::Application.configure do 
    # Settings specified here will take precedence over those in config/application.rb 

    config.action_mailer.delivery_method = :smtp 
    ActionMailer::Base.perform_deliveries = true 


ActionMailer::Base.smtp_settings    = { 
     :address    => "smtp.gmail.com", 
     :port     => "587", 
     :domain    => "localhost:3000", 
     :enable_starttls_auto => true, 
     :authentication  => "plain", 
     :user_name   => "[email protected]", 
     :password    => "my_pw" 
    } 

我得到這個,當我通過控制檯運行代碼:

ruby-1.9.2-p180 :017 > UserMailer.activation_needed_email(u).deliver 
ActionView::Template::Error: ActionView::Template::Error 
    from /Users/x/.rvm/gems/ruby-1.9.2-p180/gems/activemodel-3.0.10/lib/active_model/attribute_methods.rb:392:in `method_missing' 
    from /Users/x/.rvm/gems/ruby-1.9.2-p180/gems/activerecord-3.0.10/lib/active_record/attribute_methods.rb:46:in `method_missing' 
    from /Users/x/sample_app/app/views/user_mailer/activation_needed_email.text.erb:1:in `_app_views_user_mailer_activation_needed_email_text_erb__925048320772673370_2171058260_3164940035285331741' 
    from /Users/x/.rvm/gems/ruby-1.9.2-p180/gems/actionpack-3.0.10/lib/action_view/template.rb:135:in `block in render' 
    from /Users/x/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.10/lib/active_support/notifications.rb:54:in `instrument' 
    from /Users/x/.rvm/gems/ruby-1.9.2-p180/gems/actionpack-3.0.10/lib/action_view/template.rb:127:in `render' 
    from /Users/x/.rvm/gems/ruby-1.9.2-p180/gems/actionpack-3.0.10/lib/action_view/render/rendering.rb:59:in `block in _render_template' 
    from /Users/x/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.10/lib/active_support/notifications.rb:52:in `block in instrument' 
    from /Users/x/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.10/lib/active_support/notifications/instrumenter.rb:21:in `instrument' 
    from /Users/x/.rvm/gems/ruby-1.9.2-p180/gems/activesupport-3.0.10/lib/active_support/notifications.rb:52:in `instrument' 
    from /Users/x/.rvm/gems/ruby-1.9.2-p180/gems/actionpack-3.0.10/lib/action_view/render/rendering.rb:56:in `_render_template' 
    from /Users/x/.rvm/gems/ruby-1.9.2-p180/gems/actionpack-3.0.10/lib/action_view/render/rendering.rb:26:in `render' 
    from /Users/x/.rvm/gems/ruby-1.9.2-p180/gems/actionpack-3.0.10/lib/abstract_controller/rendering.rb:115:in `_render_template' 
    from /Users/x/.rvm/gems/ruby-1.9.2-p180/gems/actionpack-3.0.10/lib/abstract_controller/rendering.rb:109:in `render_to_body' 
    from /Users/x/.rvm/gems/ruby-1.9.2-p180/gems/actionpack-3.0.10/lib/abstract_controller/rendering.rb:102:in `render_to_string' 
    from /Users/x/.rvm/gems/ruby-1.9.2-p180/gems/actionpack-3.0.10/lib/abstract_controller/rendering.rb:93:in `render' 
... 7 levels... 
    from /Users/x/.rvm/gems/ruby-1.9.2-p180/gems/actionmailer-3.0.10/lib/action_mailer/base.rb:673:in `mail' 
    from /Users/x/sample_app/app/mailers/user_mailer.rb:14:in `activation_needed_email' 
    from /Users/x/.rvm/gems/ruby-1.9.2-p180/gems/actionpack-3.0.10/lib/abstract_controller/base.rb:150:in `process_action' 
    from /Users/x/.rvm/gems/ruby-1.9.2-p180/gems/actionpack-3.0.10/lib/abstract_controller/base.rb:119:in `process' 
    from /Users/x/.rvm/gems/ruby-1.9.2-p180/gems/actionpack-3.0.10/lib/abstract_controller/rendering.rb:41:in `process' 
    from /Users/x/.rvm/gems/ruby-1.9.2-p180/gems/actionmailer-3.0.10/lib/action_mailer/old_api.rb:75:in `process' 
    from /Users/x/.rvm/gems/ruby-1.9.2-p180/gems/actionmailer-3.0.10/lib/action_mailer/base.rb:471:in `process' 
    from /Users/x/.rvm/gems/ruby-1.9.2-p180/gems/actionmailer-3.0.10/lib/action_mailer/base.rb:466:in `initialize' 
    from /Users/x/.rvm/gems/ruby-1.9.2-p180/gems/actionmailer-3.0.10/lib/action_mailer/base.rb:450:in `new' 
    from /Users/x/.rvm/gems/ruby-1.9.2-p180/gems/actionmailer-3.0.10/lib/action_mailer/base.rb:450:in `method_missing' 
    from (irb):17 
    from /Users/x/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.10/lib/rails/commands/console.rb:44:in `start' 
    from /Users/x/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.10/lib/rails/commands/console.rb:8:in `start' 
    from /Users/x/.rvm/gems/ruby-1.9.2-p180/gems/railties-3.0.10/lib/rails/commands.rb:23:in `<top (required)>' 
    from script/rails:6:in `require' 

編輯: 這是電子郵件模板吃了:

Welcome to PolyHerd.com, <%= @user.username %> 
=============================================== 

Congratulations, you are now a part of Poly Herd, 
your username is: <%= @user.username %>. 

To activate your account, just follow this link: <%= @url %>. 

Thanks for joining and have a great day! 
+0

什麼是模板是什麼樣子? –

+0

@Dave Newton我甚至不確定它是什麼意思,當它指的是模板。 – Tony

+0

電子郵件內容有一個模板,對嗎? –

回答

0

我沒有得到任何錯誤,但郵件不出去。 看着你的域名,我很想改變我的。我也在開發模式。我將其更改爲localhost:3000,郵件現在正在通過。

你們搖滾!!!

西蒙

相關問題