您的邮件程序的配置应该/可以在两者中定义development
and production
这个配置的目的是当你使用这个的时候设置这个actionmailer
将使用这些 SMTP 选项。您可以有一个简单的邮件程序,如下所示:
Mailer
class UserMailer < ActionMailer::Base
default :from => DEFAULT_FROM
def registration_confirmation(user)
@user = user
@url = "http://portal.herokuapp.com/login"
mail(:to => user.email, :subject => "Registered")
end
end
控制器
def create
@title = 'Create a user'
@user = User.new(params[:user])
if @user.save
UserMailer.registration_confirmation(@user).deliver
redirect_to usermanagement_path
flash[:success] = 'Created successfully.'
else
@title = 'Create a user'
render 'new'
end
end
所以这里发生的事情是当create
正在使用操作这会触发邮件程序UserMailer
查看上面的 UserMailer,它使用 ActionMailer 作为基础。按照下面所示的 SMTP 设置,可以在两者中定义config/environments/production.rb
和发展.rb
您将拥有以下内容:
config.action_mailer.default_url_options = { :host => 'portal.herokuapp.com' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => 'smtp.gmail.com',
:port => 587,
:domain => 'gmail.com',
:user_name => '[email protected]',
:password => 'pass',
:authentication => 'login',
:enable_starttls_auto => true
}
如果您想在开发模式下定义 SMTP 设置,您可以替换
config.action_mailer.default_url_options = { :host => 'portal.herokuapp.com' }
with
config.action_mailer.default_url_options = { :host => 'IP ADDRESS HERE:3000' }
这应该是一个足够彻底的解释,可以让您朝着正确的方向开始。