3

我正在尝试在我的 Rails 应用程序中设置电子邮件操作,并且我想在本地测试邮件功能。我关注了这个 RailscastTimeout::Error(execution expired) ,但是每当我尝试发送邮件时,发送邮件都会 引发错误。

配置/环境/development.rb

  config.action_mailer.delivery_method = :smtp
  config.action_mailer.perform_deliveries = true
  config.action_mailer.raise_delivery_errors = true

配置/初始化程序/setup_mail.rb

ActionMailer::Base.smtp_settings = {
  :address              => 'smtp.gmail.com',
  :port                 => 587,
  :domain               => 'recipes.dev',
  :user_name            => 'myemail@gmail.com',
  :password             => '*******',
  :authentication       => 'plain',
  :enable_starttls_auto => true
}

邮件程序/user_mailer.rb

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

  def test_email(user)
    @email = user.email
    @name = user.name
    mail(:to => @email, :subject => 'test e-mail')
  end
end

控制器/users_controller.rb

UserMailer.test_email(@user).deliver

任何帮助,将不胜感激。

4

1 回答 1

0

尝试将您的 smpt_setting 端 development.rb 设置为:

config.action_mailer.smtp_settings = {
  :address              => 'smtp.gmail.com',
  :port                 => 587,
  :domain               => 'recipes.dev',
  :user_name            => 'myemail@gmail.com',
  :password             => '*******',
  :authentication       => 'plain',
  :enable_starttls_auto => true
}

你不需要 setup_mail.rb

请查看http://guides.rubyonrails.org/action_mailer_basics.html#example-action-mailer-configuration

于 2013-07-31T17:25:40.597 回答