前提・実現したいこと
railsチュートリアルの第11章
アカウント有効化するために、メイラーを使用したのですが、エンコードがquoted-printableになり、プレビューに「=3D」などのコードが入ってしまう。
チュートリアルの見本は「7bit」になっている。
メイラーのプレビュー
UserMailer#account_activation: processed outbound mail in 39.1ms Sent mail to rei@mail.com (8.1ms) Date: Thu, 11 Apr 2019 14:20:13 +0900 From: noreply@example.com To: rei@mail.com Message-ID: <5caece8d36edc_22e63fd7b3711720293fc@xxx.local.mail> Subject: Account activation Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="--==_mimepart_5caece8d356db_22e63fd7b3711720292f1"; charset=UTF-8 Content-Transfer-Encoding: 7bit ----==_mimepart_5caece8d356db_22e63fd7b3711720292f1 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hi =E7=B6=BE=E6=B3=A2=E3=83=AC=E3=82=A4,=0D =0D Welcome to the Sample App! Click on the link below to activate your accou= nt:=0D =0D http://localhost:3000/account_activations/UIYKxqawmwt9Nx1okrfigg/edit?ema= il=3Drei%40mail.com=0D =0D ----==_mimepart_5caece8d356db_22e63fd7b3711720292f1 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <!DOCTYPE html>=0D <html>=0D <head>=0D <meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Dutf= -8" />=0D <style>=0D /* Email styles need to be inline */=0D </style>=0D </head>=0D =0D <body>=0D <h1>Sample App</h1>=0D =0D <p>Hi =E7=B6=BE=E6=B3=A2=E3=83=AC=E3=82=A4,</p>=0D =0D <p>=0D Welcome to the Sample App! Click on the link below to activate your accou= nt:=0D </p>=0D =0D <a href=3D"http://localhost:3000/account_activations/UIYKxqawmwt9Nx1okrfi= gg/edit?email=3Drei%40mail.com">Activate</a>=0D </body>=0D </html>=0D ----==_mimepart_5caece8d356db_22e63fd7b3711720292f1-- Redirected to http://localhost:3000/ Completed 302 Found in 316ms (ActiveRecord: 9.6ms)
該当のソースコード
Content-Transfer-Encoding: quoted-printable
期待する結果(railsチュートリアルの見本)
UserMailer#account_activation: processed outbound mail in 292.4ms Sent mail to michael@michaelhartl.com (47.3ms) Date: Mon, 06 Jun 2016 20:17:41 +0000 From: noreply@example.com To: michael@michaelhartl.com Message-ID: <f2c9222494c7178e@mhartl-rails-tutorial-3045526.mail> Subject: Account activation Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="--==_mimepart_5755da6513e89_f2c9222494c71639"; charset=UTF-8 Content-Transfer-Encoding: 7bit ----==_mimepart_5755da6513e89_f2c9222494c71639 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Hi Michael Hartl, Welcome to the Sample App! Click on the link below to activate your account: https://rails-tutorial-mhartl.c9users.io/account_activations/ -L9kBsbIjmrqpJGB0TUKcA/edit?email=michael%40michaelhartl.com ----==_mimepart_5755da6513e89_f2c9222494c71639 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 7bit <!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> <h1>Sample App</h1> <p>Hi Michael Hartl,</p> <p> Welcome to the Sample App! Click on the link below to activate your account: </p> <a href="https://rails-tutorial-mhartl.c9users.io/account_activations/ -L9kBsbIjmrqpJGB0TUKcA/edit?email=michael%40michaelhartl.com">Activate</a> </body> </html> ----==_mimepart_5755da6513e89_f2c9222494c71639--
該当のソースコード
Content-Transfer-Encoding: 7bit
試したこと
1.Userメイラーの生成
$ rails generate mailer UserMailer account_activation password_reset
2.テキストビューの変更
app/views/user_mailer/account_activation.text.erb
Hi <%= @user.name %>, Welcome to the Sample App! Click on the link below to activate your account: <%= edit_account_activation_url(@user.activation_token, email: @user.email) %>
3.HTMLビューの変更
app/views/user_mailer/account_activation.html.erb
<h1>Sample App</h1> <p>Hi <%= @user.name %>,</p> <p> Welcome to the Sample App! Click on the link below to activate your account: </p> <%= link_to "Activate", edit_account_activation_url(@user.activation_token, email: @user.email) %>
4.development環境のメール設定
config/environments/development.rb
# Don't care if the mailer can't send. # メイラー config.action_mailer.raise_delivery_errors = true config.action_mailer.delivery_method = :test host = 'localhost:3000' config.action_mailer.default_url_options = { host: host, protocol: 'http' } config.action_mailer.perform_caching = false
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/04/11 06:50