0

我正在使用 gem 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 回答