我一直在发送电子邮件如下:
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
并且一直运行良好,但现在我想发送多封电子邮件,因为我需要处理 1000 多个用户。所以我一直在读到我可以用 X-SMTPAPI 标头来完成这个所以我尝试了这个
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
但是 Sendgrid 只是通过电子邮件发送给 email2@gmail.com 而不是标题。我怎样才能解决这个问题?