I set up a test script nearly directly from the readme file to play with substitutions and sections. Subs work, but sections don't seem to have any effect.
#based on the repo sendgrid/sendgrid-ruby
require 'sendgrid-ruby'
# Or as a block
client = SendGrid::Client.new do |c|
c.api_user = 'USERNAME'
c.api_key = 'PASSWORD'
end
mail = SendGrid::Mail.new do |m|
m.to = 'to@example.com'
m.from = 'from@example.com'
m.subject = 'Hello ' + Time.now.strftime('%Y%m%d%H%M%S') + '-charger-'
m.text = '-bomber- I heard you like pineapple. keep this other thing! <br /> -charge-'
end
mail.smtpapi.set_sections({'-charge-' => 'This ship is useful.'})
mail.smtpapi.add_section('-bomber-', ['Only for sad kansans.'])
mail.smtpapi.add_substitution('keep', ['secret']) # sub = {keep: ['secret']}
mail.smtpapi.add_substitution('other', ['one', 'two']) # sub = {keep: ['secret'], other: ['one', 'two']}
mail.smtpapi.add_section('-charger-', ['This ship is useless.'])
mail.smtpapi.add_substitution('useless', ['ITWORKED']) # sub = {keep: ['secret']}
#client.send(SendGrid::Mail.new(to: 'example@example.com', from: 'taco@cat.limo', subject: 'Hello world!', text: 'Hi there!', html: '<b>Hi there!</b>'))
puts client.send(mail)
# {"message":"success"}
The email I receive is:
Subject:
Hello 20141015123749-charger-
Message:
-bomber- I heard you like pineapple. secret this one thing! <br /> -charge-
"keep" is replaced, "other" is replaced, but "-charger-", "-bomber-", and "-charge-" don't get replaced
I set up a test script nearly directly from the readme file to play with substitutions and sections. Subs work, but sections don't seem to have any effect.
The email I receive is:
Subject:
Message:
"keep" is replaced, "other" is replaced, but "-charger-", "-bomber-", and "-charge-" don't get replaced