私はレールに非常に慣れていないので、ここに明らかな何かが欠けている場合はご容赦ください!
ActionMailer が私のメールに本文を送信しません。ヘッダーはうまくいきますが、本文はありません。
私にも同様の質問がいくつかありますが、解決策はどれもうまくいきません.2日間インターネットをトロールして尻尾を追いかけましたが、すべて役に立ちませんでした!
私はDeviseを実行していますが、それはメールをうまく送信します!
actionmailer がテンプレートをレンダリングしていないという結論に達しました。
内部メールを実行している simple-private-messages gem があり、そのコントローラーで、ユーザーがアプリでメッセージを受け取ったときにメールを送信しています。
私がこれまでに試したこと:
デリバーを使用して!届ける代わりに
user_mailer.erb で content_type:、template_path:、template_name: を指定する
テンプレートを指定するために user_mailer でブロックを実行します。すなわち
format.html { render 'welcome_email' } format.text { render :text => 'welcome_email.txt.erb' })
テンプレートが正しいディレクトリにあるにもかかわらず、これはエラーになります(私は思う)
ActionView::MissingTemplate (Missing template user_mailer/welcome_email with {:locale=[:en], :formats=>[:text], :handlers=>[:erb, :builder, :arb, :coffee, :haml]}.
テンプレートの可能なすべての名前プレフィックス ... template.html.erb、template.text.html.erb、template.erb
環境から 'config.active_support.deprecation = :log' を削除しようとしても、投稿で修正される可能性があることが示唆されていました! (どうやっても、私には手がかりがありません)
問題の原因となっている場合に備えて、メールにパラメータをドロップしました!
Rails の構成に関する慣習につまずいた場合に備えて、私が好むカスタム メソッドではなく、API に従ってwelcome_email メソッドを使用するようにしました。
ActionMailer のログを設定しましたが、エラーは表示されないようで、メールは送信されたと表示されますが、テンプレートへの参照はありません。上記の解決策は私が覚えているものですが、それらはすべて他の人にとってはうまくいきましたが、私にとってはそうではありません! 私は逃したものに完全に途方に暮れています!
助けてくれてありがとう!もうコードが必要な場合はお知らせください。
実行中のレール 3.2.3、Ruby 1.9、ActionMailer 3.2.3
ここにgitリポジトリへのリンクを投稿する人は誰もいないようです。その理由はありますか?喜んで提供しますが、他の誰も提供していないようですので、今のところ提供しません.
障害の発見に役立つコードを次に示します...
user_mailer.rb
class UserMailer < ActionMailer::Base
default :from => "myemail@gmail.com"
def welcome_email(user)
@user = user
@url = "http://example.com/login"
mail(:to => user.email, :subject => "Welcome to My Awesome Site")
end
end
messages_controller.rb
def create
@message = Message.new(params[:message])
@message.sender = @user
@message.recipient = User.find(params[:message][:to])
if @message.save
flash[:notice] = "Message sent"
UserMailer.welcome_email(@message.recipient).deliver!
redirect_to user_messages_path(@user)
else
render :action => :new
end
終わり
Welcome_email.html.erb
<!DOCTYPE html>
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
</head>
<body>
<h1>Welcome</h1>
</body>
</html>
Welcome_email.text.erb
Text Text Text!!!
コンソール サーバーからのログ
Sent mail to user@me.com (14517ms)
Date: Thu, 20 Jun 2013 18:13:23 +0200
From: myapp@gmail.com
To: user@me.com
Message-ID: <31c32a237e61c_b73c3ff82f78328e051786@my-app.com.mail>
Subject: Welcome to My Awesome Site
Mime-Version: 1.0
Content-Type: text/plain;
charset=UTF-8
Content-Transfer-Encoding: 7bit
Redirected to http://localhost:3000/users/1/messages
Completed 302 Found in 14674ms (ActiveRecord: 15.3ms)