Mailer error missing template

后端 未结 8 1015
谎友^
谎友^ 2021-02-18 21:25

Hello,

I have problem with ActionMailer, when I try to execute action:

rake send_email

I get a error:



        
相关标签:
8条回答
  • 2021-02-18 21:59

    I had the same problem. Restarting sidekiq solved it for me.

    0 讨论(0)
  • 2021-02-18 22:02

    I renamed my method and it worked. Maybe the name of the method can't be mail or mailer...

    0 讨论(0)
  • 2021-02-18 22:07

    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
    
    0 讨论(0)
  • 2021-02-18 22:08

    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.)

    0 讨论(0)
  • 2021-02-18 22:15
    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.

    0 讨论(0)
  • 2021-02-18 22:16

    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

    0 讨论(0)
提交回复
热议问题