【问题标题】:Ruby On Rails - Not sending email in development modeRuby On Rails - 在开发模式下不发送电子邮件
【发布时间】:2012-08-29 07:30:55
【问题描述】:

类似的问题 Rails contact form not working

指南:https://github.com/thomasklemm/email_form_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

  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_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

开发.rb

  config.action_mailer.delivery_method = :smtp
  config.action_mailer.perform_deliveries = true
  config.action_mailer.smtp_settings = {
      :address              => "smtp.gmail.com",
      :port                 => 587,
      :domain               => "mydomain.com",
      :user_name            => "myemail@gmail.com",
      :password             => "mypassword",
      :authentication       => :plain,
      :enable_starttls_auto => true
  }

  config.action_mailer.default_url_options = {
      :host => "localhost:3000"
  }

命令输出

在 2012-09-04 22:10:40 +0700 为 127.0.0.1 开始 POST "/email" 由 HomeController#send_email_form 作为 HTML 参数处理: {"utf8"=>"√", "authenticity_token"=>"w39BLqCrjTMm4RRi/Sm5hZoEpcw46 npyRy/RS0h48x0=", "消息"=>{"name"=>"anonymousxxx", "email"=>"anonymousxxx@yahoo.com", "subject"=>"Test", "body"=>"send email"}, "commit"=>"Create Message"} 重定向到 localhost:3000/home/contact Completed 302 发现在 1ms (ActiveRecord: 0.0ms)

但是电子邮件(消息)没有收到我的电子邮件,..

【问题讨论】:

    标签: ruby-on-rails-3.2 actionmailer active-attr


    【解决方案1】:

    如果您只想看到电子邮件被触发,有一种方法可以使用操作邮件配置传递方法将电子邮件保存到本地文件系统并指定您要保存的位置。我通常保存到 tmp/mail。

    【讨论】:

      【解决方案2】:

      如果在开发模式下记录说Completed,它不会告诉电子邮件已发送。您需要在config/environment/development.rb 中设置config.action_mailer.raise_delivery_errorstrue 值,如果电子邮件发送不正确会显示一些错误。

      Rails.application.configure do
          ## other stuff
          config.action_mailer.raise_delivery_errors = true
          ## other stuff
      end
      

      【讨论】:

        猜你喜欢
        • 2014-12-05
        • 1970-01-01
        • 2014-12-06
        • 2013-06-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-06-15
        • 2016-07-04
        相关资源
        最近更新 更多