我使用电子邮件发送服务 (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
此方法的问题在于它不会转发原始邮件的附件。
如何更改此邮件程序以转发原始邮件中的所有附件(包括在 html 正文中引用的内联图像)?
最佳答案
以下代码片段可能对您有所帮助
options[:attachments].each do |attachment|
attachments[attachment.original_filename] = File.read(attachment.tempfile)
end
关于ruby-on-rails - ActionMailer - 使用原始 RFC822 邮件的附件创建新邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51067078/