Rails mailer mandrill设置

时间:2014-11-29 11:40:37

标签: ruby-on-rails email actionmailer mandrill

我正在尝试使用Mandrill设置电子邮件,因此我可以在生产中测试它。我是rails的新手,无法确定是否必须在特殊情况下配置'from'(发件人)电子邮件。所有在线指南都没有帮助我。我已经在Mandrill中设置了一个帐户并进行了相应的配置。

development.rb     Rails.application.configure做       #此处指定的设置将优先于config / application.rb中的设置。

  # In the development environment your application's code is reloaded on
  # every request. This slows down response time but is perfect for development
  # since you don't have to restart the web server when you make code changes.
  config.cache_classes = false

  # Do not eager load code on boot.
  config.eager_load = false

  # Show full error reports and disable caching.
  config.consider_all_requests_local       = true
  config.action_controller.perform_caching = false

  # Print deprecation notices to the Rails logger.
  config.active_support.deprecation = :log

  # Raise an error on page load if there are pending migrations.
  config.active_record.migration_error = :page_load

  # Debug mode disables concatenation and preprocessing of assets.
  # This option may cause significant delays in view rendering with a large
  # number of complex assets.
  config.assets.debug = true

  # Adds additional error checking when serving assets at runtime.
  # Checks for improperly declared sprockets dependencies.
  # Raises helpful error messages.
  config.assets.raise_runtime_errors = true

  # Raises error for missing translations
  # config.action_view.raise_on_missing_translations = true


  # ActionMailer Config
  config.action_mailer.default_url_options = { :host => 'localhost:3000' }
  config.action_mailer.delivery_method = :smtp
  # change to true to allow email to be sent during development
  config.action_mailer.perform_deliveries = true
  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.default :charset => "utf-8"

  config.action_mailer.smtp_settings =
  {
    :address   => "smtp.mandrillapp.com",
    :port      => 587,
    :user_name => ENV[:email],
    :password  => "ENV[:password]"
  }


end

邮件收发器

class ContactMailer < ActionMailer::Base
  default from: "ajn123@vt.edu"


  def contact_user(message)
    @message = message
    mail(to: @message.email, subject: "Contact from AJNORTON.com").deliver
  end

end

记录(没有发送电子邮件,但没有给出错误)

Sent mail to ajn123@vt.edu (459.0ms)
Date: Sat, 29 Nov 2014 06:30:36 -0500
From: ajn123@vt.edu
To: ajn123@vt.edu
Message-ID: <5479ae5c53708_7ef13fce5cda9c2828447@Air.mail>
Subject: Contact from AJNORTON.com
Mime-Version: 1.0
Content-Type: text/html;
 charset=UTF-8
Content-Transfer-Encoding: 7bit

<div>
  <p>
    tntn
  </p>
  <p>
    ajn123@vt.edu
  </p>
  <p>
    ntntnt
  </p>
</div>


ContactMailer#contact_user: processed outbound mail in 478.3ms

1 个答案:

答案 0 :(得分:1)

尝试启用TLS:在ActionMailer :: Base.smtp_settings上放置“enable_starttls_auto:true”和“authentication :: plain”

config.action_mailer.smtp_settings =
{
    :address   => "smtp.mandrillapp.com",
    :port      => 587,
    :user_name => ENV[:email],
    :password  => ENV[:password],
    :authentication => :plain,
    :enable_starttls_auto => true
}

另外,您的ENV [:密码]错误。你不应该在引号内。

WRONG:

:password  => "ENV[:password]"

正确:

:password  => ENV[:password]