I will be sending bulk emails from a Rails app and plan on using SendGrid. I am assuming that it is best to send a separate email to each recipient (as opposed to using BCC
This is how I've done it in Rails 4
class NewsMailer < ApplicationMailer
include SendGrid
sendgrid_category :use_subject_lines
default from: 'My App! '
def mass_mailer(news)
# Pass it in template
@news = news
# Custom method to get me an array of emails ['user1@email.com', 'user2@email.com',...]
array_of_emails = @news.recipients.pluck(:email)
# You can still use
# headers["X-SMTPAPI"] = { :to => array_of_emails }.to_json
sendgrid_recipients array_of_emails
mail to: 'this.will.be.ignored@ignore.me', subject: 'Weekly news'
end
end