0

私は宝石https://github.com/sendgrid/sendgrid-rubyを使用しています

SendGrid には、次のようなトランザクション メール テンプレートがあります。

<%body%>
Hello :name!, what's up
your number is :number.
This is the transactional footer

変数を渡す方法:number:name??

ありがとう、

4

1 に答える 1

0

テンプレートに関連する のセクションをREADME確認してください。

メールを送信するユーザー モデルがあるとします。

# assuming some users
recipients = []

users.each do |user|
  recipient = SendGrid::Recipient.new(user.email)
  recipient.add_substitution('name', 'some name')
  recipient.add_substitution('number', 1234)

  recipients << recipient
end

# then initialize a template
template = SendGrid::Template.new('MY_TEMPLATE_ID')

# create the client
client = SendGrid::Client.new(api_user: my_user, api_key: my_key)

# set some defaults
mail_defaults = {
  from: 'admin@email.com',
  html: '<h1>I like email</h1>',
  text: 'I like email',
  subject: 'Email is great',
}

mailer = SendGrid::TemplateMailer.new(client, template, recipients)

# then mail the whole thing at once
mailer.mail(mail_defaults)
于 2015-11-30T06:46:50.110 に答える