我有一个带有简单邮件程序的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
答案 0 :(得分:9)
默认情况下,不会在开发中发送邮件。要启用此功能,您应该像这样调整development.rb
:
config.action_mailer.perform_deliveries = true
您也可以启用config.action_mailer.raise_delivery_errors = true
来提高投放错误。
<强>更新强>
由于提供了无效的电子邮件,结果是导致问题的default from
。