Ruby on rails 3.2 RubyonRails-在开发模式下不发送电子邮件
类似问题 指南: rails 3.2.x app\models\message.rbRuby on rails 3.2 RubyonRails-在开发模式下不发送电子邮件,ruby-on-rails-3.2,actionmailer,active-attr,Ruby On Rails 3.2,Actionmailer,Active Attr,类似问题 指南: rails 3.2.x app\models\message.rb class Message include ActiveAttr::Model include ActiveModel::Validations attribute :name attribute :email attribute :subject attribute :body attr_accessible :name, :email, :subject, :body
class Message
include ActiveAttr::Model
include ActiveModel::Validations
attribute :name
attribute :email
attribute :subject
attribute :body
attr_accessible :name, :email, :subject, :body
validates_presence_of :name
validates_presence_of :email
validates :email, email_format: { message: "is not looking like a valid email address"}
validates_presence_of :subject
validates_length_of :body, maximum: 500
end
app\mailers\contact\u form.rb
class ContactForm < ActionMailer::Base
default from: "myemail@gmail.com"
default to: "myemail@gmail.com"
def email_form(message)
@message = message
mail subject: "#{message.subject} #{message.name}"
mail body: "#{message.body}"
end
end
命令输出
于2012-09-04 22:10:40+0700开始为127.0.0.1发布“/电子邮件”
HomeController#发送(电子邮件)表单作为HTML参数进行处理:
{“utf8”=>“√", "真实性\u令牌“=>”w39BLqCrjTMm4RRi/Sm5hZoEpcw46
npyRy/RS0h48x0=“,”消息“=>{”名称“=>”匿名XXX”,
“电子邮件”=>”anonymousxxx@yahoo.com“,”主题“=>”测试“,”正文“=>”发送
电子邮件“}”,提交“=>”创建邮件“}重定向到
本地主机:3000/主页/联系人在1ms内完成302
(活动记录:0.0ms)
但是email(message)no receive my email,…如果您只想查看已触发的电子邮件,可以使用action mailer config delivery方法将电子邮件保存到本地文件系统,并指定保存位置。我通常保存到tmp/mail 如果在开发模式下log say的
已完成
,则不会说明电子邮件已发送。您需要使用config/environment/development.rb
中的true
值设置config.action\u mailer.raise\u delivery\u errors
,如果电子邮件发送不正确,它将显示一些错误
Rails.application.configure do
## other stuff
config.action_mailer.raise_delivery_errors = true
## other stuff
end
Rails.application.configure do
## other stuff
config.action_mailer.raise_delivery_errors = true
## other stuff
end