Rails 3邮件问题

时间:2012-12-03 21:19:39

标签: ruby-on-rails email actionmailer

我正在关注这个railscast以熟悉rails 3中的ActionMailer,但是我没有收到要发送电子邮件的运气。

我认为我的问题可能出在我的setup_mail.rb文件中,有人可以在这里发现问题吗?我正试图通过我的Gmail帐户发送电子邮件jbdyno@gmail.com

ActionMailer::Base.smtp_settings = {
  :address              => "smtp.gmail.com",
  :port                 => 587,
  :domain               => "gmail.com",
  :user_name            => "jbdyno",
  :password             => "I PUT MY PASSWORD HERE",
  :authentication       => "plain",
  :enable_starttls_auto => true
}

其他档案

user_mailer.rb

class UserMailer < ActionMailer::Base
  default from: "jbdyno@gmail.com"

  def registration_confirmation(user)
    mail(:to => user.email, :subject => "Registered")
  end

end

registration_confirmation.text.erb

Thanks for registering!

users_controller.rb

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

    respond_to do |format|
      if @user.save
        UserMailer.registration_confirmation(@user).deliver
        format.html { redirect_to @user, notice: 'User was successfully created.' }
        format.json { render json: @user, status: :created, location: @user }
      else
        format.html { render action: "new" }
        format.json { render json: @user.errors, status: :unprocessable_entity }
      end
    end
  end

感谢!!!

1 个答案:

答案 0 :(得分:1)

在您尝试发送电子邮件的环境配置中,您可能需要添加config.action_mailer.delivery_method = :smtp

有关使用gmail的完整示例配置,请参阅Rails Guides on ActionMailer (Setup with Gmail)

确保在更改配置文件后重新启动开发服务器。