2
我遵循RailsCasts上的教程(發送電子郵件修訂版本)。我不得不在「config」中更改開發文件,因爲它沒有正常工作。一直以來,當我嘗試添加一個攔截器(告訴Rails發送郵件給我),它將停止發送給用戶。如果我禁用它,它會將它發送給用戶,但不是給我。我根本沒有任何錯誤。謝謝 !Rails 3郵件攔截器衝突
Here are my files:
My config/development.rb file:
ActionMailer::Base.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:user_name => "[email protected]",
:password => 'admin',
:authentication => "plain",
:enable_starttls_auto => true
}
User controller:
UserMailer.signup_confirmation(@user).deliver
User mailer file:
app/mailers/user_mailer.rb
class UserMailer < ActionMailer::Base
default from: "[email protected]"
def signup_confirmation(user)
@user = user
mail to: user.email, subject: "Sign Up Confirmation"
end
end
lib/development_mail_interceptor.rb file
class DevelopmentMailInterceptor
def self.delivering_email(message)
message.subject = "[#{message.to}] #{message.subject}"
message.to = "[email protected]"
end
end
config/initiliazers/setup_mail.rb
require 'development_mail_interceptor'
ActionMailer::Base.register_interceptor(DevelopmentMailInterceptor) if
Rails.env.development?