In a Rails 5.1 ActionMailer, I want to attach a Mail object to an e-mail:
def attach_mail(original_email)
attachments['original-email.eml'] = { mime_type: 'message/rfc822', encoding: '7bit', content: original_email.to_s }
mail to: 'postmaster', subject: 'mail should be attached'
end
However, this does not produce valid e-mails. Thunderbird lists the attachment with size '0'. Horde lists the attachment with correct size, but does not recognize it as an e-mail.
I've tried variations of the attachments line:
attachments['original-email.eml'] = original_email
attachments['original-email.eml'] = { content: original_email.to_s }
attachments['original-email.eml'] = { mime_type: 'message/rfc822', content: original_email.to_s }
but none of these result in an e-mail with an e-mail attachment.
What's the solution?