I have been sending emails as follows:
def send
ActionMailer::Base.mail(content_type: "text/html", from: "\"name\" <email@gmail.com>", to: "email2@gmail.com", subject: "subject", body: "<h1>Hi</h1>" , priority: 2).deliver
end
And has been working well but now I want to send multiple emails because I need to handle 1000+ users. So I have been reading that I can accomplish this with X-SMTPAPI header so I tried this
def send_all
recipients = ["users1@gmail.com", "users2@gmail.com"]
ActionMailer::Base.headers["X-SMTPAPI"] = { :to => recipients }.to_json
ActionMailer::Base.mail(content_type: "text/html", from: "\"name\" <email@gmail.com>", to: "email2@gmail.com", subject: "subject", body: "<h1>Hi</h1>" , priority: 2).deliver
end
But Sendgrid just emails to email2@gmail.com and not the headers. How can I fix this?