当我试图通过Sorcery使用激活时,为什么我的Rails 3 Action Mailer不发送电子邮件?

时间:2011-09-17 02:23:40

标签: ruby-on-rails email actionmailer

我使用巫术进行电子邮件激活,并且我遵循了他们的wiki教程:https://github.com/NoamB/sorcery/wiki/User-Activation。 我很确定问题在于发送电子邮件,而不是激活,因为这是另一个问题。

以下是User Mailer的代码:

class UserMailer < ActionMailer::Base
  default :from => "my_gmail_account@gmail.com"

  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            => "my_gmail_account@gmail.com",
      :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!

1 个答案:

答案 0 :(得分:0)

我没有收到任何错误,但是邮件没有出去。 在查看您的域名时,我很想改变我的域名。我也处于开发模式。我将其更改为localhost:3000,邮件现在正在通过。

你们摇滚!!!

西蒙