我有一个运行良好的 rails 3.2.3 应用程序,并提供设计创建的邮件消息,注册确认和密码忘记邮件消息以设置新密码。
但是,我有不同的地方要发送邮件通知。
这是我的Notifier
模型。
# encoding: utf-8
class Notifier < ActionMailer::Base
default from: "no-reply@domain.com"
default to: "admin@domain.com"
def new_post_submitted(post)
@post = post
mail(subject: "Anúncio enviado: #{@post.title}")
end
def new_message(message)
@message = message
mail(subject: "Mensagem de contato: #{@message.subject}")
end
end
控制器调用:
def create
@message = Message.new(params[:message])
if @message.valid?
Notifier.new_message(@message).deliver
redirect_to(root_path, :notice => "Obrigado. Sua Mensagem enviada com sucesso")
else
flash.now.alert = "Por favor preencha todos os campos."
render :new
end
end
日志输出说它已交付:
Started POST "/contato" for 187.57.102.168 at 2012-08-31 11:28:51 +0900
Processing by ContactController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"TVdmDYCA4x3JVi+9pMcpY7OSU/P1lE9enLiFJlK9W1M=", "message"=>{"name"=>"kleber", "email"=>"test@gmail.com", "subject"=>"teste", "body"=>"hello there"}, "commit"=>"Enviar"}
Rendered notifier/new_message.html.erb (0.1ms)
Sent mail to admin@domain.com (152ms)
Redirected to http://www.domain.com/
Completed 302 Found in 158ms (ActiveRecord: 0.0ms)
以及我的config/production.rb
文件中的以下配置。
ActionMailer::Base.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
:address => "localhost",
:port => 25,
:domain => "domain.com",
:authentication => :login,
:user_name => "admin@domain.com",
:password => "mypassword",
:enable_starttls_auto => false
}
关于这里发生了什么的任何线索?