2016-01-15 13 views
8

私は過去3年間4レール4、工夫&マンドリルのメール

のRailsでアプリを作るしようとしているが、私が把握するのに苦労してきた工夫/ omniauth(私はまだ取得しようとしていますそれは働く)。

私が試してみるうちに主な問題を踏み出し、これを生きる意志を見つけながら、私はMandrillで電子メールを設定しようとしました。

私は私が一緒に従うしようとしています。このチュートリアル、が見つかりました:私はmandrill_devise_mailer.rb

class MandrillDeviseMailer < Devise::Mailer 

    def confirmation_instructions(record, token, opts={}) 
    # code to be added here later 
    end 

    def reset_password_instructions(record, token, opts={}) 
    options = { 
     :subject => "Reset your password", 
     :email => record.email, 
     :global_merge_vars => [ 
     { 
      name: "password_reset_link", 
      # content: "http://www.example.com/users/password/edit?reset_password_token=#{token}" 
      content: "http://www.cr.com/users/password/edit?reset_password_token=#{token}" 

     }, 

     { 
      name: "PASSWORD_RESET_REQUEST_FROM", 
      content: record.full_name 
     } 
     ], 
     :template => "Forgot Password" 
    } 
    mandrill_send options 
    end 

    def unlock_instructions(record, token, opts={}) 
    # code to be added here later 
    end 

    def mandrill_send(opts={}) 
    message = { 
     :subject=> "#{opts[:subject]}", 
     :from_name=> "Reset Instructions", 
     # :from_email=>"[email protected]", 
     :from_email=>["PROD_WELCOME"], 
     :to=> 
      [{"name"=>"#{opts[:full_name]}", 
       "email"=>"#{opts[:email]}", 
       "type"=>"to"}], 
     :global_merge_vars => opts[:global_merge_vars] 
     } 
    sending = MANDRILL.messages.send_template opts[:template], [], message 
    rescue Mandrill::Error => e 
     Rails.logger.debug("#{e.class}: #{e.message}") 
     raise 
    end 
end 

上記とどのような彼らは、チュートリアルで行っているとの違いと呼ばれるメーラーを持ってhttps://nvisium.com/blog/2014/10/08/mandrill-devise-and-mailchimp-templates/

を以下のとおりです。

私のメールチンパンジーマンドリルテンプレートで

、私が持っている:

<a href="*|password_reset_link|*">Change my password </a> 

手順をリセットする電子メールが届いたら、パスワード変更フォームの下にある下線付きのリンクが表示されます。私は 'パスワードをリンクテキストを隠すラベルにする'ようにしたい。

私は間違ったことを誰にでも見せてもらえますか? from_email`にメールアドレスのように見えない[ "PROD_WELCOME"] ``に設定されている。ここで

+0

を作成する方法であります私。 – VNO

+0

ありがとうございます - ENVを設定して電子メールを送信するように設定しましたが、変数 – Mel

+0

を取り込むのではなく、* || *の間に単語を表示しますか?デフォルトのマージ言語としてハンドルバーを使用していますか?設定の下であなたのマンドリル[送信オプション](https://mandrillapp.com/settings/sending-options)に行き、適切なマージ言語が有効になっているかどうかを確認してください。 –

答えて

-2

は、私はあなたが `カスタムDeviseMailer

class MyDeviseMailer < Devise::Mailer 
    default template_path: 'devise/mailer' # to make sure that your mailer uses the devise views 

    def reset_password_instructions(record, token, opts={}) 
    opts['from_email'] = "[email protected]" 
    opts['from_name'] = "Password Reset" 
    #Rails.logger.mail.info "reset_password_instructions #{record.to_json} \n #{token.to_json} \n #{opts.to_json}" 
    super 
    end 

end 

https://github.com/plataformatec/devise/wiki/How-To:-Use-custom-mailerAdd dynamic value in devise email subject

+0

ハイドミトリー、 mailchimp/mandrillを使用しようとしているように見えません。とにかくありがとう。 – Mel

+0

Mandrill APIはopts ['from_email']とopts ['from_name'] paramsを必要としました。私はhttp://www.alanverga.com/blog/2014/01/03/custom-rails-mailer-and-mandrillとhttps://robots.thoughtbot.com/how-to-send- transactional-emails-from-mandrill –

+0

しかし、これらのオプションも私のファイルにあります。私の問題は、リンクが私が表現した方法でリンクとしてフォーマットしないということです。その代わりに、リンクはタグの内側に表示され、リンクのラベルはテキストとして表示されます。 – Mel