我按照RailsCasts教程(发送电子邮件修订版)。我不得不在" config"中更改开发文件。因为它不能正常工作。总是当我尝试添加一个拦截器(告诉Rails也向我发送电子邮件)时它会停止发送给用户。如果我禁用它,它会将它发送给用户但不发送给我。我根本没有任何错误。谢谢!
Here are my files:
My config/development.rb file:
ActionMailer::Base.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:user_name => "admin@gmail.com",
: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: "admin@gmail.com"
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 = "admin@gmail.com"
end
end
config/initiliazers/setup_mail.rb
require 'development_mail_interceptor'
ActionMailer::Base.register_interceptor(DevelopmentMailInterceptor) if
Rails.env.development?
答案 0 :(得分:1)
您正在设置电子邮件,而不是添加电子邮件。
message.to = "admin@gmail.com"
尝试以下其中一项:
message.to << "admin@gmail.com"
message.to += "admin@gmail.com"