4

サインアップ時に ActionMailer を設定するのに問題があります:

config/initializers/setup_mail.rb

ActionMailer::Base.smtp_settings = {
 :address              => "smtp.gmail.com",
 :port                 => "587",
 :domain               => "mail.gmail.com",
 :user_name            => "my_gmail_user_name",
 :password             => "my_gmail_pw",
 :authentication       => "plain",
 :enable_starttls_auto => true
}

ActionMailer::Base.default_url_options[:host] = "localhost:3000"
Mail.register_interceptor( DevelopmentMailInterceptor ) if Rails.env.development?

users_controller.rb

def create
  @user = User.new( params[:user] )

  respond_to do |format|
    if @user.save
      UserMailer.welcome_email( @user ).deliver

      format.html{ redirect_to( @user, :notice => 'Account successfully created.' ) }
      format.json{ render :xml => @user, :status => :created, :location => @user }
    else
      format.html { render :action => "new" }
      format.xml  { render :xml => @user.errors, :status => :unprocessable_entity }
    end
end

app/mailers/user_mailer.rb

class UserMailer < ActionMailer::Base
  default :from "no-reply@myapp.com"

  def welcome_email( user )
    @user = user
    @url = "http://localhost:3000/login"
    mail( :to => user.email, :subject => 'Welcome to app' )
  end
end

lib/development_mail_interceptor.rb

class DevelopmentMailInterceptor
  def self.delivering_email(message)
    message.subject = "#{message.to} #{message.subject}"
    message.to = "mydump@email.com"
  end
end

のダンプ メールにメールが送信されませんDevelopmentMailInterceptor

4

1 に答える 1

1

Gmailはアナルです!とにかく別のSMTPホストを使用できますか?過度に積極的なスパム検出のために、彼らは「潜在的なスパム」と見なすSMTP要求を黙って拒否すると思います。あなたの場合の潜在的なスパムとは、「mail.gmail.com」(あなたの場合は「email.com」)以外のアドレスから送信された電子メールを意味します。

RailsアプリのSMTPホストとしてGmailを使用することは提案を失うことだと思います。私は、Railsアプリにgodaddy.com(smtpout.secureserver.net)を使用しており、問題はありません。

于 2012-05-03T03:33:49.273 に答える