Rails 3 - Action Mailer不发送消息

时间:2012-03-14 15:42:56

标签: ruby-on-rails

我有一个按钮' buy'链接到'评论'像这样的页面:

<%= button_to 'Buy', review_hvacs_path(:b => true, :h => hvac, :a => params[:a], :s => params[:s]) %>

这会调用控制器中的审核操作,&#39; hvacs_controller&#39;其中包含......

@buy = params[:b]
if !@buy.nil?
  @currentHvac = Hvac.find(params[:h])
  @supplier = HvacSupplier.find(@currentHvac.hvac_supplier_id)
  Notifier.gmail_message(@supplier)
end

如果用户按下购买按钮,我会尝试发送消息。

我的开发环境如下:

  # Don't care if the mailer can't send
  config.action_mailer.raise_delivery_errors = false

  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {
    :enable_smarttls_auto => true,
    :address => 'smtp.gmail.com',
    :port => 587,
    :authentication => :plain,
    :domain => 'gmail.com',
    :username => '<my email address>@gmail.com',
    :password => '<my password>'
  }

...我的邮件看起来像这样:

class Notifier < ActionMailer::Base
  default from: "user@address.com"

  # Subject can be set in your I18n file at config/locales/en.yml
  # with the following lookup:
  #
  #   en.notifier.gmail_message.subject
  #
  def gmail_message(supplier)
    @greeting = "HVAC Equipment Purchase"
    @supplier = supplier

    mail(:to => supplier.email, :subject => "HVAC Equipment Enquiry")
  end
end

消息:

Notifier#gmail_message

<%= @greeting %>, I am interesting in purchasing replacement equipment, and would like an evaluation.

有人有任何见解吗?我错过了什么?如果我遗漏任何细节,我会发布它们。

1 个答案:

答案 0 :(得分:1)

Notifier.gmail_message(@supplier).deliver