문제

I need to send massive email,I will use for brackground job Delayed Job, and have to create the email message in 3 languages (de, en, re), How can I cache the view so it doesn't have to create each time I'm calling the the mail method.

도움이 되었습니까?

해결책

The deliver method is the one that sends the email, so you can do this:

def send_emails
  # You can set here the email with attachments and all stuff
  mail = MyMailer.send_message("demo@example.com")
  body = mail.html_part.body

  User.all.each do |u|
    mail.to = u.email
    mail.html_part.body = body.gsub(/user_id/, u.id)
    mail.deliver
  end
end

Of course it's better if you set this method for background processing.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top