2

我遵循 RailsCasts 教程(发送电子邮件修订版)。我不得不更改“配置”中的开发文件,因为它无法正常工作。总是当我尝试添加拦截器(告诉 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?        
4

1 回答 1

1

您将电子邮件设置为,而不是添加到它。

message.to = "admin@gmail.com" 

尝试其中之一:

message.to << "admin@gmail.com" 
message.to += "admin@gmail.com" 
于 2012-12-18T18:39:02.460 回答