【问题标题】:Ruby on Rails Mailer not sending email in development modeRuby on Rails Mailer 在开发模式下不发送电子邮件
【发布时间】:2014-12-05 08:19:37
【问题描述】:

我有一个带有简单邮件程序的 Ruby on Rails 应用程序,如下所示:

class EventMailer < ActionMailer::Base

  default from: "example.com"

  def welcome_email(event, customer)
    @event = event
    @customer = customer
    mail :subject => "Test", :to => @customer.email
  end
end

我的 action_mailer 设置如下所示:

config.action_mailer.smtp_settings = {
    :address   => "smtp.mandrillapp.com",
    :port      => 587, # ports 587 and 2525 are also supported with STARTTLS
    :enable_starttls_auto => true, # detects and uses STARTTLS
    :user_name => "my_email",
    :password  => "my_password", # SMTP password is any valid API key
    :authentication => 'login', # Mandrill supports 'plain' or 'login'
    :domain => 'yourdomain.com', # your domain to identify your server when connecting
  }

我也有客户注册,它可以正确发送电子邮件。但是当我尝试在我的控制台中运行时:

EventMailer.welcome_email(Event.last, Customer.last).deliver

它不发送电子邮件。有什么问题?我没有想法...

编辑: 我的其余配置

  config.action_mailer.default_url_options = { :host => 'localhost:3000' }
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.perform_deliveries = true
  config.action_mailer.raise_delivery_errors = true

【问题讨论】:

  • 您的控制台有错误吗?
  • 不,控制台中没有任何错误...
  • 顺便说一句,您的default from 似乎很奇怪。应该放一封电子邮件。
  • 哦,这种事情经常发生 :) 很高兴它有帮助!

标签: ruby-on-rails ruby actionmailer


【解决方案1】:

默认情况下不会在开发中发送邮件。要启用此功能,您应该像这样调整您的 development.rb

config.action_mailer.perform_deliveries = true

您也可以启用config.action_mailer.raise_delivery_errors = true 来引发递送错误。

更新

原来是default from导致了问题,因为提供了无效的电子邮件。

【讨论】:

猜你喜欢
  • 2012-08-29
  • 1970-01-01
  • 2013-05-21
  • 1970-01-01
  • 2014-12-06
  • 2015-08-23
  • 2013-06-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多