smtpapi-ruby gemを使用してSendgridにレールメーラーを結び付けるにはどうすればよいですか?私は彼らのlimited documentationに従ってきましたが、私の電子メールは通過していません。普通の電子メールを送信するとSendGridの実装がうまく動作することを確認しました。これは私が持っているものです。SendGridテンプレートを使用しているRailsメーラー
user_controller.rb
def create
@user = User.new(user_params)
respond_to do |format|
if @user.save
format.html { redirect_to @user, notice: 'User was successfully created.' }
format.json { render :show, status: :created, location: @user }
header = Smtpapi::Header.new
header.add_to(@user.email)
header.add_substitution('user', [@user.name])
header.add_substitution('body', "You've registered! This is from the controller.")
header.add_filter('templates', 'enable', 1)
header.add_filter('templates', 'template_id', 'xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxx')
header.to_json
UserNotifier.welcome(header).deliver
else
format.html { render :new }
format.json { render json: @user.errors, status: :unprocessable_entity }
end
end
end
メーラー/ user_notifier.rb
class UserNotifier < ApplicationMailer
default from: "[email protected]"
def welcome(header)
headers['X-SMTPAPI'] = hdr.to_json
mail(subject: "Welcome to the site!")
end
end
ビュー/ user_notifier/welcome.html.erb
<html>
<body>
Hi -user-<br />
Thanks so much for joining us!
<p>-body-</p>
Thanks,<br />
The Microblog Team
</body>
</html>
SendGridのアクティビティログに何も表示されないので、少なくともそこに送信されるわけではありません。少なくとも私の推測です。
私は間違っていますか?
OKをSendgridドキュメントをチェックアウトするが、今私は#のための '未定義のローカル変数やメソッド'「ヘッダを取得 ' –
Godzilla74
あなた' ApplicationMailer' inherithsを'ActionMailer :: Base'から? 'class UserNotifier
Aguardientico
' headers ['X-SMTPAPI'] = hdr.to_json'に行を変更しなければならなかったので、まだ実行していませんスルーします。 – Godzilla74