-
Notifications
You must be signed in to change notification settings - Fork 322
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extend Gem with additional Template and Recipient Functionality (round 2) #28
Conversation
Awesome! We'll get to this as soon as we can. |
This will add filters to the smtpapi gem: https://github.com/sendgrid/smtpapi-ruby The template_id will be passed in like other attributes to mail Example: ``` mail = SendGrid::Mail.new do |m| m.to = '[email protected]' m.from = '[email protected]' m.subject = 'Hello world!' m.text = 'I heard you like pineapple.' m.template_id = 1234 end ```
To help encapsulate the substitution logic for templates and how they correlate with email recipients, this model has been introduced. The benefit is now something like this is possible: ```ruby template = Template.new(TEMPLATE_ID) users = User.find(['[email protected]', '[email protected]']) users.each do |user| recipient = Recipient.new(user) recipient.add_substitution(:name, user.name) recipient.add_substitution(:location, user.location) template.add_recipient(recipient) end ``` The next step will be to integrate the `Recipient` and `Template` with `Mail`.
This will add an accessor for the template without an initialization through a template_id
This is the final piece of abstracting recipients, templates and the sending of mail. The use of this would look like: ```ruby users = User.where(email: ['[email protected]', '[email protected]']) recipients = [] users.each do |user| recipient = SendGrid::Recipient.new(user.email) recipient.add_substitution('first_name', user.first_name) recipient.add_substitution('city', user.city) recipients << recipient end template = SendGrid::Template.new('MY_TEMPLATE_ID') client = SendGrid::Client.new(api_user: my_user, api_key: my_key) mail_defaults = { from: '[email protected]', html: '<h1>I like email</h1>', text: 'I like email' subject: 'Email is great', } mailer = TemplateMailer.new(client, template, recipients) mailer.mail(mail_defaults) ```
Extend Gem with additional Template and Recipient Functionality (round 2)
Thanks for contributing to SendGrid Open Source! We think it's awesome when community members contribute to our projects and want to celebrate that. The following link will ask you to authenticate with Github (so we can verify your identity). You'll then be asked for your shipping address so that we can send you a thanks for contributing. Once again, thank you! |
Glad to contribute and thanks for the shirt! |
update readme - add license, remove logo from bottom, add ToC
@thinkingserious
After #23, I have successfully added my changes to the new version of the gem.
Template
to aMail
object.Mail
object has atemplate
when the Mail'sto_h
method is called, it automatically adds the required template parameters to thesmtpapi
header.README
.Recipient
of template substitutions.
SMTPAPI
Template
template_id
and managingRecipients
SMTPAPI
TemplateMailer
Template
and 1 to manyRecipients
Mail
andClient
objects to handle actual deliveryrequire
pattern.