I have been sending emails as follows:
def send
ActionMailer::Base.mail(content_type: "text/html", from: "\"name\" <[email protected]>", to: "[email protected]", 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 = ["[email protected]", "[email protected]"]
ActionMailer::Base.headers["X-SMTPAPI"] = { :to => recipients }.to_json
ActionMailer::Base.mail(content_type: "text/html", from: "\"name\" <[email protected]>", to: "[email protected]", subject: "subject", body: "<h1>Hi</h1>" , priority: 2).deliver
end
But Sendgrid just emails to [email protected] and not the headers. How can I fix this?
I did it as follows, I don't think is the best solution because I'm loading Sendgrid config again but it worked
Also I needed to
require 'mail'
in the class