Reputation: 1865
My Rails mailer worked perfectly a few months ago. I didn't deal with it for a long time, and I don't remember changing anything either. But now, no email is sent when I activate the mailer via my console, although I don't receive any errors.
I triple-checked that the email addresses and passwords are correct. I also set up my email according to this answer. But no emails are sent. If something is going wrong, shouldn't I at least be getting an error in my console?
I'm using 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
Console
$ 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>>
Upvotes: 0
Views: 2179
Reputation: 1601
Use Mailer methods deliver
,deliver_now
or deliver_later
in your controller
or Model
UserMailer.notify(User.first).deliver
Upvotes: 1
Reputation: 2378
You have to call .deliver_now
or .deliver_later
on the result of your notify
method. Check out how to use ActionMailer for more information.
Upvotes: 0