【发布时间】:2015-10-06 14:42:22
【问题描述】:
几个月前,我的 Rails 邮件程序运行良好。我很长时间没有处理它,我也不记得改变了什么。但是现在,当我通过控制台激活邮件程序时,不会发送任何电子邮件,尽管我没有收到任何错误。
我反复检查了电子邮件地址和密码是否正确。我也根据this answer设置了我的邮箱。但是没有发送电子邮件。如果出现问题,我至少不应该在控制台中收到错误吗?
我使用的是 Rails 4.0.10。
config/environments/development.rb
Website::Application.configure do
config.action_mailer.delivery_method = :smtp
config.action_mailer.default_url_options = { host:'localhost', port: '3000' }
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.gmail.com',
port: 587,
domain: 'localhost:3000',
user_name: 'xxxxxx@xxxxxxx',
password: 'password',
authentication: 'plain',
enable_starttls_auto: true
}
end
app/mailers/user_mailer
class UserMailer < ActionMailer::Base
default from: "xxxxxx@xxxxx"
def notify(user)
@user = user
mail(to: @user.email,subject: "subject")
end
end
控制台
$ UserMailer.notify(User.first)
Rendered user_mailer/notify.html.erb (0.4ms)
=> #<Mail::Message:2623523, Multipart: false, Headers: <From: xxxxxx@xxxxx>, <To: xxxxxxx@xxxxx>, <Subject: subject>, <Mime-Version: 1.0>, <Content-Type: text/html>>
【问题讨论】:
-
您可以在调用邮件方法的地方发布控制器操作吗?
-
@Pavan 我只是在我的开发控制台中调用它。
标签: ruby-on-rails ruby email actionmailer mailer