Why isn't my Rails 3 Action Mailer sending out an email when I'm trying to use activation through Sorcery?
I using sorcery for email activation and I've followed their wiki tutorial: https://github.com/NoamB/sorcery/wiki/User-Activation. I'm pretty sure the problem lies within sending out emails and less so towards activation because that is another issue.
Here's the code for 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
Here's my development.rb file:
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"
}
I'm getting this when I run the code through console:
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 re开发者_如何学Cnder'
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'
EDIT: Here's the email template:
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!
I was getting no error, however mails were not going out. On looking at your domain, I got tempted to change mine. Am also in development mode. I changed it to localhost:3000, and mails are now coming through.
You guys rock!!!
Simon
精彩评论