Hello,
I have problem with ActionMailer, when I try to execute action:
rake send_email
I get a error:
I had the same problem. Restarting sidekiq solved it for me.
I renamed my method and it worked. Maybe the name of the method can't be mail or mailer...
Try adding layout
class UserMailer < ActionMailer::Base
default from: "from@example.com"
layout "mailer"
def mailer(user)
@user = user
mail(to: @user.email, subject: 'Test')
end
end
It's likely that Rails just isn't finding your newly created files. If you have the spring
gem running, that could be the issue. (More on spring: https://github.com/rails/spring)
To setup terminal commands and stop running spring
:
$ bundle exec spring binstub --all
$ bin/spring stop
I tried this, then re-running my app with rails s
. That didn't work so then try closing the terminal completely and rebooting your computer. Run rails s
and try testing with rails c
in a second tab:
mail = UserMailer.mailer(User.last)
That finally worked for me, hopefully it'll help some of you!
(Some of these steps may be redundant.)
class UserMailer < ActionMailer::Base
default from: "from@example.com"
layout "mailer"
def mailer(user)
@user = user
mail(to: @user.email, subject: 'Test')
end
end
Add a html layout under layout#
mailer.html.erb
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
/* Email styles need to be inline */
</style>
</head>
<body>
<%= yield %>
</body>
</html>
Add text layout under layout #
mailer.text.erb
<%= yield %>
Use preview to check your email based on your test framework.
Could you publish a minimalist Github repository reproducing your error?
You may try to generate your mailer in order to check you are not forgetting something:
bundle exec rails generate mailer mailer_classname mailer_viewname
In your case:
bundle exec rails generate mailer user_mailer mailer