2017-07-20 2 views
0

Ich habe E-Mails wurden zu senden, wie folgt:mehrere E-Mails mit Sendgrid senden nicht mit X-SMTPAPI Header arbeiten

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 

Und gut gearbeitet hat, aber jetzt möchte ich mehrere E-Mails senden, weil ich umgehen müssen 1000+ Benutzer. So habe ich gelesen, dass ich das mit X-SMTPAPI Header erreichen kann, so habe ich versucht, diese

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 

Aber Sendgrid nur E-Mails an [email protected] und nicht die Header. Wie kann ich das beheben?

Antwort

0

Ich habe es wie folgt, ich glaube nicht, ist die beste Lösung, weil ich wieder Sendgrid Config bin Laden, aber es funktionierte

def send 
    Mail.defaults do 
     delivery_method :smtp, { :address => 'smtp.sendgrid.net', 
           :port  => 587, 
           :domain => 'sendgrid.com', 
           :user_name => 'yourSendGridUsername', 
           :password => 'yourSendGridPassword', 
           :authentication => 'plain', 
           :enable_starttls_auto => true } 
    end 

     recipients = ["[email protected]", "[email protected]"] 

     mail = Mail.deliver do 
      header['X-SMTPAPI'] = { :to => recipients }.to_json 
      to "[email protected]" 
      from '[email protected]' 
      subject 'Ruby Example using X-SMTPAPI header' 
      text_part do 
      body 'You would put your content here, but I am going to say: Hello world!' 
      end 
      html_part do 
      content_type 'text/html; charset=UTF-8' 
      body '<b>Hello world!</b><br>Glad to have you here!' 
      end 
     end 

end 

Auch musste ich require 'mail' in der Klasse

Verwandte Themen