I use an email delivery service to send emails (Sparkpost), and everytime one of these emails is replied, I receive a JSON that contains: the reply mail body as HTML (body_html), the reply mail body as text (body_text) and the original RFC822 (email_rfc822) for the reply message.
After receiving this JSON, I need to forward this email to another recipient. Currently, I use the following mailer to achieve that:
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
The problem with this approach is that it does not forward the attachments of the original message.
How could change this mailer to also forward all the attachments from the original message (including inline images that are referenced on the html body)?
The following snippet might help you
options[:attachments].each do |attachment|
attachments[attachment.original_filename] = File.read(attachment.tempfile)
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With