質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Q&A

解決済

1回答

3550閲覧

railsチュートリアル_メイラーのエンコードがquoted-printableになる

tri_se28

総合スコア16

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

1グッド

0クリップ

投稿2019/04/11 06:24

前提・実現したいこと

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
Lichtenstein👍を押しています

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

日本語が入ったUTF-8は、7ビットの範囲に収まらないので、Content-Transfer-Encoding: 7bitとして送ることはできないのではないかと思います。

あと、「=0D」(たしかCRコードだったはず)も入っています。

投稿2019/04/11 06:35

maisumakun

総合スコア145184

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

tri_se28

2019/04/11 06:50

早速のご回答ありがとうございます!解決しました! ユーザーの名前を日本語にしていたのが原因でした。 英語で登録したところContent-Transfer-Encoding: 7bitとなり、正常にメールを送ることが出来ました。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問