# ActionMailer Attach Original Message

**URL:** <https://www.ruby-forum.com/t/actionmailer-attach-original-message/117108>\
**Category:** Rails\
**Created:** [October 13, 2007, 1:55am UTC](https://www.ruby-forum.com/t/actionmailer-attach-original-message/117108 "2007-10-13T01:55:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![xmg-eric](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/f04885/32.png) [@xmg-eric](https://www.ruby-forum.com/u/xmg-eric)\
**Post date:** [October 13, 2007, 1:55am UTC](https://www.ruby-forum.com/t/actionmailer-attach-original-message/117108/1 "2007-10-13T01:55:54Z")

</div>

I have a mailer setup to receive messages for processing data. If the  
message sent is not correct then I send back an email telling the user  
of their problem. I want to attach the original message and I have it  
sort of working, but if the original message has an attachment that  
attachment doesn’t seem to display in my Email client (Thunderbird).  
Here is what I have:

def invalid\_email(error, email)  
recipients email.from  
from email.to  
subject ‘Data Import Failed!’  
body :error =\> error  
part :body =\> email.to\_s, :content\_type =\> ‘message/rfc822’  
end

In this method “error” is some error message (a string) and email is the  
TMail object that came in from the receive method.

Any ideas?

Eric

---

<div class="post-metadata">

**Author:** ![xmg-eric](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/x/f04885/32.png) [@xmg-eric](https://www.ruby-forum.com/u/xmg-eric)\
**Post date:** [October 13, 2007, 5:28pm UTC](https://www.ruby-forum.com/t/actionmailer-attach-original-message/117108/2 "2007-10-13T17:28:08Z")

</div>

Eric,

I’m doing the same thing in one of my apps, but we opted not to use  
ActionMailer in order to preserve the contents. Instead, we jut use  
Net::SMTP to send it directly. Below is what I’m using using; for  
clarity, I omitted exception handling code that surrounds the  
Net::SMTP block:

require ‘net/smtp’

smtp\_settings = ActionMailer::Base.smtp\_settings

Net::SMTP.start(smtp\_settings[:address], smtp\_settings[:port],  
smtp\_settings[:domain], smtp\_settings[:user\_name],  
smtp\_settings[:password], smtp\_settings[:authentication]) do |smtp|  
smtp.send\_message(raw, FROM\_ADDRESS, to\_address)  
end

-Mike Subelsky  
Baltimore, MD
