# ActionMailer plain/text attachments

**URL:** <https://www.ruby-forum.com/t/actionmailer-plain-text-attachments/177416>\
**Category:** Rails\
**Created:** [October 16, 2009, 6:55pm UTC](https://www.ruby-forum.com/t/actionmailer-plain-text-attachments/177416 "2009-10-16T18:55:50Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![destiney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f07891/32.png) [@destiney](https://www.ruby-forum.com/u/destiney)\
**Post date:** [October 16, 2009, 6:55pm UTC](https://www.ruby-forum.com/t/actionmailer-plain-text-attachments/177416/1 "2009-10-16T18:55:50Z")

</div>

Does anyone know how to prevent a plain/text attachment to be inline  
within an email? Is it as simple as changing the content\_type to an  
application type?

My app (not a web app) is using ActionMailer outside of rails and  
everything is working like a charm, but I don’t like that a plain text  
attachment is being placed inline within the email. The attachment is  
supporting data or db that I used to create the email. It is actually  
a YAML flat file DB. It is quite long and will grow each week up to a  
point. Most everyone I’m emailing will not care to see the data  
within their email, but a few of my fellow “geeks” will, so a file  
would be best.

here is a code snippet:

attachment :content\_type =\> “text/plain”,  
:filename =\> File.basename(yaml\_file),  
:body =\> File.read(yaml\_file)

Can I force the attachment to be an attachment file and not be inline?

If this is simple, sorry I bothered everyone.

Thanks,

GregD

---

<div class="post-metadata">

**Author:** ![destiney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f07891/32.png) [@destiney](https://www.ruby-forum.com/u/destiney)\
**Post date:** [October 16, 2009, 7:09pm UTC](https://www.ruby-forum.com/t/actionmailer-plain-text-attachments/177416/2 "2009-10-16T19:09:53Z")

</div>

Okay, it looks like it is up to the recieving end’s app or browser to  
render it inline because I dumped the TMail objects and the content-  
disposition was “attachment; filename=db.yml”. I’m thinking of trying  
a different content-type like application/octet-stream or send a zip/  
gz file instead.

How do you send a zip/gzip/bzip2 file? The File.read might not work  
correctly below are my thoughts.

Thanks,

GregD

---

<div class="post-metadata">

**Author:** ![destiney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f07891/32.png) [@destiney](https://www.ruby-forum.com/u/destiney)\
**Post date:** [October 16, 2009, 7:38pm UTC](https://www.ruby-forum.com/t/actionmailer-plain-text-attachments/177416/3 "2009-10-16T19:38:15Z")

</div>

Greg D. wrote:  
[…]

> The attachment is  
> supporting data or db that I used to create the email. It is actually  
> a YAML flat file DB. It is quite long and will grow each week up to a  
> point. Most everyone I’m emailing will not care to see the data  
> within their email, but a few of my fellow “geeks” will, so a file  
> would be best.

How big will this thing grow? If most recipients don’t want to see it,  
why are you wasting their disk space with it? If I were one of your  
recipients and you were sending me weekly messages with big attachments,  
I think I’d be pretty upset. I’d suggest that it would be better to  
provide a URL where the full data file can be downloaded by those who  
are interested.

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![destiney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f07891/32.png) [@destiney](https://www.ruby-forum.com/u/destiney)\
**Post date:** [October 16, 2009, 8:09pm UTC](https://www.ruby-forum.com/t/actionmailer-plain-text-attachments/177416/4 "2009-10-16T20:09:00Z")

</div>

Well, it wont get THAT large. Maybe 200K. But, I see your point. I  
don’t have have a place to host the file right now. I’d like to send  
it compressed since it is plain text. I was even thinking of sending  
an xls file summary, but that would be larger.

Does anyone know if I compress it into another file using ZLib gzip  
format, how to send it? Actually, any binary file. The examples all  
show File.read and will that work with binary files. I would think  
not.

I’ll look into hosting the 2 files instead. But, it would be nice to  
see an example of sending something other than an image file.

GregD

On Oct 16, 1:38 pm, Marnen Laibow-Koser \<rails-mailing-l…@andreas-

---

<div class="post-metadata">

**Author:** ![destiney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f07891/32.png) [@destiney](https://www.ruby-forum.com/u/destiney)\
**Post date:** [October 16, 2009, 9:14pm UTC](https://www.ruby-forum.com/t/actionmailer-plain-text-attachments/177416/5 "2009-10-16T21:14:27Z")

</div>

Greg D. wrote:

> Well, it wont get THAT large. Maybe 200K. But, I see your point. I  
> don’t have have a place to host the file right now. I’d like to send  
> it compressed since it is plain text. I was even thinking of sending  
> an xls file summary, but that would be larger.
> 
> Does anyone know if I compress it into another file using ZLib gzip  
> format, how to send it? Actually, any binary file. The examples all  
> show File.read and will that work with binary files. I would think  
> not.
> 
> I’ll look into hosting the 2 files instead. But, it would be nice to  
> see an example of sending something other than an image file.

Image files are binary files (well, except SVG). Any technique for  
sending an image file should work for GZip or any other binary format.

> GregD

## Best,

Marnen Laibow-Koser  
[http://www.marnen.org](http://www.marnen.org)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![destiney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/f07891/32.png) [@destiney](https://www.ruby-forum.com/u/destiney)\
**Post date:** [October 17, 2009, 12:46am UTC](https://www.ruby-forum.com/t/actionmailer-plain-text-attachments/177416/6 "2009-10-17T00:46:28Z")

</div>

Take a look at:  
[http://www.webmaster-toolkit.com/mime-types.shtml](http://www.webmaster-toolkit.com/mime-types.shtml)

There are several registered mime types for zip and gzip files.  
These will give you valid values for :content\_type.
