Rails 邮件程序山魈设置
Posted
技术标签:
【中文标题】Rails 邮件程序山魈设置【英文标题】:Rails mailer mandrill setup 【发布时间】:2015-01-27 21:19:48 【问题描述】:我正在尝试在开发中使用 Mandrill 设置电子邮件,以便在生产中对其进行测试。我是 Rails 新手,无法确定是否必须在特殊邮件中配置“发件人”(发件人)电子邮件。所有在线指南都没有帮助我。我已经在 Mandrill 建立了一个帐户并进行了相应的配置。
开发.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】:尝试启用 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[:password] 是错误的。你不应该把引号括起来。
错误:
:password => "ENV[:password]"
正确:
:password => ENV[:password]
【讨论】:
以上是关于Rails 邮件程序山魈设置的主要内容,如果未能解决你的问题,请参考以下文章
在 mandrill 模板中使用 Ruby/rails 变量