没有收到联系表格的邮件

时间:2014-04-16 20:07:01

标签: ruby-on-rails

我有联系表单设置,我正在使用gmail。但是我没有收到任何邮件。我收到消息发送的闪光警报,但是在日志中查看电子邮件是否正在创建。

有人可以看看并帮助我吗?

contact_mailer.rb:

  default :from => "no-reply@domain.com"

    def new_contact(contat)
      @contact = message
    end
  end

development.rb:

  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {
    address:              'smtp.gmail.com',
    port:                 587,
    domain:               'gmail.com',
    user_name:            'mygmail@gmail.com',
    password:             'password',
    authentication:       'plain',
    enable_starttls_auto: true  }

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

联系人控制器:

   def create
      @contact = Contact.new(params[:message])
      if @contact.valid?
        ContactMailer.new_contact(@contact).deliver
        flash[:notice] = "Message sent! Thank you for contacting us."
        redirect_to root_url
      else
        render :action => 'new'
      end

联系模式:

  def initialize(attributes={})
      attributes && attributes.each do |name, value|
        send("#{name}=", value) if respond_to? name.to_sym 
      end
    end

日志:

Started POST "/contacts" for 127.0.0.1 at 2014-04-16 15:59:35 -0400
Processing by ContactsController#create as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"WN19FGciesn2QUiaMtxv4Lwo48tRTkFBSud7OPGRTts=", "contact"=>{"email"=>"test@test.com", "content"=>"This is a bot."}, "commit"=>"Send Message"}
  User Load (0.4ms)  SELECT `users`.* FROM `users` WHERE `users`.`auth_token` = 'Mqy5_1kyb4hAsrmB9Q0fug' LIMIT 1
Redirected to http://localhost:3000/
Completed 302 Found in 6ms (ActiveRecord: 0.4ms)


Started GET "/" for 127.0.0.1 at 2014-04-16 15:59:35 -0400
Processing by UsersController#index as HTML
  User Load (0.4ms)  SELECT `users`.* FROM `users` WHERE `users`.`auth_token` = 'Mqy5_1kyb4hAsrmB9Q0fug' LIMIT 1
  Rendered searches/_new.html.erb (5.5ms)
  User Load (0.3ms)  SELECT `users`.* FROM `users`
  Rendered users/index.html.erb within layouts/application (8.6ms)
   (0.7ms)  SELECT COUNT(*) FROM `conversations` INNER JOIN `notifications` ON `notifications`.`conversation_id` = `conversations`.`id` AND `notifications`.`type` IN ('Message') INNER JOIN `receipts` ON `receipts`.`notification_id` = `notifications`.`id` WHERE `notifications`.`type` = 'Message' AND `receipts`.`mailbox_type` = 'inbox' AND `receipts`.`trashed` = 0 AND `receipts`.`deleted` = 0 AND `receipts`.`receiver_id` = 2 AND `receipts`.`receiver_type` = 'User' AND `receipts`.`is_read` = 0
Completed 200 OK in 81ms (Views: 78.5ms | ActiveRecord: 1.4ms)

1 个答案:

答案 0 :(得分:1)

在开发中,默认情况下不会发送邮件,请添加到development.rb

config.action_mailer.raise_delivery_errors = true
config.action_mailer.perform_deliveries = true

编辑:没有注意到,您的邮件程序方法没有使用mail方法,是吗?不应该是这样的:

邮件(致:@contact,主题:'我很棒的邮件)