Làm cách nào để gắn trong đường gửi thư của tôi đến Sendgrid bằng đá quý smtpapi-ruby? Tôi đã theo dõi limited documentation của họ, nhưng email của tôi không đi qua, tôi đã xác minh rằng việc triển khai SendGrid của tôi hoạt động tốt khi chỉ gửi một email đơn giản, vì vậy không phải vậy. Đây là những gì tôi có:Rails Mailer bằng cách sử dụng SendGrid Template
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
bưu phẩm/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
views/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>
Tôi không nhìn thấy bất cứ điều gì đi qua trên nhật ký hoạt động SendGrid, vì vậy nó thậm chí không nhận được gửi ở đó, ít nhất đó là dự đoán của tôi.
Tôi đang làm gì sai?
Ok, có ý nghĩa, nhưng bây giờ tôi nhận được 'không xác định biến hoặc phương pháp địa phương' tiêu đề' cho # ' –
Godzilla74
' ApplicationMailer' inheriths của bạn từ 'ActionMailer :: Base'? nếu không, bạn có thể thử sử dụng như sau: 'class UserNotifier
Aguardientico
Phải thay đổi dòng thành' tiêu đề ['X-SMTPAPI'] = hdr.to_json' thì nó sẽ gửi ... vẫn không đi mặc dù vậy. – Godzilla74