sendgrid-rubyでカテゴリを設定する

https://sendgrid.com/docs/API_Reference/SMTP_API/categories.htmlが、https://github.com/sendgrid/sendgrid-rubyというgemライブラリで実際にカテゴリを設定する方法がよく分からなかった。

中のコードを読んだりググったりしてるうちに、以下のやり方で送信できることが確認できたのでメモ

client = SendGrid::Client.new(api_key: '0ACkvN4O3jUPEM8HzUAKdvQ7PT1NlGXlIX1jS0x7Gc1wo2ggx07Pd1tllkzUI4mayeRPP')
template = SendGrid::Template.new('aabbccdd-aaaa-bbbb-cccc-ddddeeeeffff')

recipient = SendGrid::Recipient.new('some-user@example.com')
recipients = [recipient]


# ここでX-SMTPAPIヘッダーに相当するデータを構築する
header = Smtpapi::Header.new
header.add_category('My Category No123')

mail_defaults = {
  from: 'noreply@example.com',
  from_name: 'Official',
}
mailer = SendGrid::TemplateMailer.new(client, template, recipients)
mailer.mail(mail_defaults)

続きを読む sendgrid-rubyでカテゴリを設定する