fel*_*cst 5 ruby email ruby-on-rails actionmailer
我使用电子邮件递送服务发送电子邮件(Sparkpost),每次回复其中一封电子邮件时,我收到的JSON包含:回复邮件正文为HTML(body_html),回复邮件正文为文本(body_text)和原始RFC822(email_rfc822)用于回复消息.
收到此JSON后,我需要将此电子邮件转发给其他收件人.目前,我使用以下邮件来实现:
class ReplyMailer < ApplicationMailer
def reply(body_html, body_text, options = {})
mail(to: options[:to], from: options[:from], reply_to: options[:reply_to], subject: options[:subject], skip_premailer: true) do |format|
format.html { render html: body_html.html_safe } if body_html.present?
format.text { render plain: body_text } if body_text.present?
end
end
end
Run Code Online (Sandbox Code Playgroud)
此方法的问题在于它不转发原始邮件的附件.
如何更改此邮件程序还转发原始邮件中的所有附件(包括在html正文中引用的内嵌图像)?
以下片段可能对您有帮助
options[:attachments].each do |attachment|
attachments[attachment.original_filename] = File.read(attachment.tempfile)
end
Run Code Online (Sandbox Code Playgroud)