【发布时间】:2014-01-28 12:00:05
【问题描述】:
我想在我的 Rails 应用程序中发送电子邮件,但我不知道为什么电子邮件没有发送到电子邮件目的地,而在我的日志中电子邮件发送。这是我在environment/development.rb 中的电子邮件发件人设置:
MyApp::Application.configure do
config.cache_classes = false
config.eager_load = false
config.consider_all_requests_local = true
config.action_controller.perform_caching = false
config.action_mailer.raise_delivery_errors = false
config.active_support.deprecation = :log
config.active_record.migration_error = :page_load
config.assets.debug = true
config.action_mailer.perform_deliveries = true
config.action_mailer.default_url_options = { :host => 'localhost:3000' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => 'gmail.com',
:user_name => 'my_username',
:password => 'my_pass',
:authentication => 'plain',
:enable_starttls_auto => true }
end
这是我的UserMailer.rb:
class UserMailer < ActionMailer::Base
def checkout(admin_email, email, ids, store_name)
@email = email
@seller = admin_email
@store_name = store_name
@orders = []
@store = Store.where("name = ?", store_name).first
ids.each do |f|
@orders << Order.find(f)
end
mail(:to => "<#{email}>", :from => "<#{admin_email}>", :subject => "checkout confirmation")
end
end
这是我的控制器中用于发送电子邮件的代码:
UserMailer.checkout(admin_email, email, ids, store.name).deliver
为什么这封电子邮件似乎已发送(根据日志)但未发送给收件人?
【问题讨论】:
-
为什么你写的越来越少然后在你的邮件之前和之后签名删除它们。
-
是的,改成
mail(:to => email, :from => admin_email, :subject => "checkout confirmation")
标签: ruby-on-rails mailer