2015-11-30 51 views

回答

0

檢查出section of the README relating to templates

假設你有要發送的電子郵件給用戶的模式:

# 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: '[email protected]', 
    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) 
+0

嘗試這樣做,得到一個錯誤。 NoMethodError(未定義方法'to_h'爲#):在以下行「mailer.mail(mail_defaults)」 – jdog