我需要发送大量的电子邮件,我将用于托管作业延迟作业,并且必须以3种语言创建电子邮件消息(de,en,re),如何缓存视图以使其不必每次我调用邮件方法时都会创建。
答案 0 :(得分:1)
传递方法是发送电子邮件的方法,因此您可以执行此操作:
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
当然,最好将此方法设置为后台处理。