# Multipart email - HTML & document files

**URL:** <https://www.ruby-forum.com/t/multipart-email-html-document-files/193970>\
**Category:** Rails\
**Created:** [August 27, 2010, 10:58am UTC](https://www.ruby-forum.com/t/multipart-email-html-document-files/193970 "2010-08-27T10:58:07Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mercurius](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/c89c15/32.png) [@mercurius](https://www.ruby-forum.com/u/mercurius)\
**Post date:** [August 27, 2010, 10:58am UTC](https://www.ruby-forum.com/t/multipart-email-html-document-files/193970/1 "2010-08-27T10:58:07Z")

</div>

What I want, and can’t seem to achieve, is to send an html email with an  
attachment. As it stands, I can do one or the other and aren’t sure how  
to get both to work.

Mailer:

[http://pastie.org/1119939](http://pastie.org/1119939)

Corresponding view:

[http://pastie.org/1119941](http://pastie.org/1119941)

Can anyone give me some assistance with this or point me to some  
relevant documentation?

Note: the attachment could be in almost any format but is likely to be a  
.doc or .pdf file.

---

<div class="post-metadata">

**Author:** ![mercurius](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/c89c15/32.png) [@mercurius](https://www.ruby-forum.com/u/mercurius)\
**Post date:** [August 31, 2010, 12:34pm UTC](https://www.ruby-forum.com/t/multipart-email-html-document-files/193970/2 "2010-08-31T12:34:05Z")

</div>

Pale H. wrote:

> What I want, and can’t seem to achieve, is to send an html email with an  
> attachment. As it stands, I can do one or the other and aren’t sure how  
> to get both to work.
> 
> Mailer:
> 
> [http://pastie.org/1128664](http://pastie.org/1128664)
> 
> Corresponding view:
> 
> [http://pastie.org/1128665](http://pastie.org/1128665)
> 
> Can anyone give me some assistance with this or point me to some  
> relevant documentation?
> 
> Note: the attachment could be in almost any format but is likely to be a  
> .doc or .pdf file.

Can anyone help me with this? It is still giving me issues. The updated  
pasties are in the quote above.

---

<div class="post-metadata">

**Author:** ![mercurius](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/c89c15/32.png) [@mercurius](https://www.ruby-forum.com/u/mercurius)\
**Post date:** [August 31, 2010, 1:01pm UTC](https://www.ruby-forum.com/t/multipart-email-html-document-files/193970/3 "2010-08-31T13:01:27Z")

</div>

Hi,

On Tue, Aug 31, 2010 at 5:34 AM, Pale H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Pale H. wrote:
> 
> > What I want, and can’t seem to achieve, is to send an html email with an  
> > attachment. As it stands, I can do one or the other and aren’t sure how  
> > to get both to work.

> **[ActionMailer::Base](https://api.rubyonrails.org/classes/ActionMailer/Base.html)**
>
> Action Mailer allows you to send email from your application using a mailer model and views. Mailer Models To use Action Mailer, you need to create a mailer model.

I suspect the answer to your problem lies in the last sentence of the  
‘Multipart Emails’ section which says:

“Implicit template rendering is not performed if any attachments or  
parts have been added to the email. This means that you’ll have to  
manually add each part to the email and set the content type of the  
email to multipart/alternative.”

The latter portion of the ‘Mailer Models’ section addresses explicit  
template rendering. Googling ‘rails mailer explicit template  
rendering’ offered up some links that look helpful. There’s one by  
Eric H. that looked like it might point the way.

HTH,  
Bill

---

<div class="post-metadata">

**Author:** ![mercurius](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/c89c15/32.png) [@mercurius](https://www.ruby-forum.com/u/mercurius)\
**Post date:** [August 31, 2010, 1:03pm UTC](https://www.ruby-forum.com/t/multipart-email-html-document-files/193970/4 "2010-08-31T13:03:13Z")

</div>

On Aug 31, 11:34 am, Pale H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Pale H. wrote:
> 
> > What I want, and can’t seem to achieve, is to send an html email with an  
> > attachment. As it stands, I can do one or the other and aren’t sure how  
> > to get both to work.

I think you’re screwing thinks up by forcing the content type to text/  
html - an email with attachments is going to be multipart. Might be  
different in 3, but in 2.3 there’s a part method that allows you to  
specify each of the parts (plain, html, attachments etc.)

Fred

---

<div class="post-metadata">

**Author:** ![mercurius](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/c89c15/32.png) [@mercurius](https://www.ruby-forum.com/u/mercurius)\
**Post date:** [August 31, 2010, 1:10pm UTC](https://www.ruby-forum.com/t/multipart-email-html-document-files/193970/5 "2010-08-31T13:10:39Z")

</div>

Frederick C. wrote:

> On Aug 31, 11:34ï¿½am, Pale H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > Pale H. wrote:
> > 
> > > What I want, and can’t seem to achieve, is to send an html email with an  
> > > attachment. As it stands, I can do one or the other and aren’t sure how  
> > > to get both to work.
> 
> I think you’re screwing thinks up by forcing the content type to text/  
> html - an email with attachments is going to be multipart. Might be  
> different in 3, but in 2.3 there’s a part method that allows you to  
> specify each of the parts (plain, html, attachments etc.)
> 
> Fred

Thank you for your replies, both of you. It is true that I need to split  
the email into different parts but the syntax is losing me.

---

<div class="post-metadata">

**Author:** ![mercurius](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/c89c15/32.png) [@mercurius](https://www.ruby-forum.com/u/mercurius)\
**Post date:** [August 31, 2010, 3:39pm UTC](https://www.ruby-forum.com/t/multipart-email-html-document-files/193970/6 "2010-08-31T15:39:31Z")

</div>

On 31 Aug 2010, at 13:10, Pale H. wrote:

> > specify each of the parts (plain, html, attachments etc.)
> > 
> > Fred
> 
> Thank you for your replies, both of you. It is true that I need to  
> split  
> the email into different parts but the syntax is losing me.

It’s a real pain, even in Rails 3 with the new mail gem (although it’s  
already a lot more streamlined). And be happy you don’t want to bring  
inline images to the mix.

This might help:  
[http://www.wetware.co.nz/blog/2010/06/sending-emails-with-rails-multipart-html-plain-with-attachments/](http://www.wetware.co.nz/blog/2010/06/sending-emails-with-rails-multipart-html-plain-with-attachments/)  
[http://iamwil.posterous.com/2312983](http://iamwil.posterous.com/2312983)

Best regards

Peter De Berdt

---

<div class="post-metadata">

**Author:** ![mercurius](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/c89c15/32.png) [@mercurius](https://www.ruby-forum.com/u/mercurius)\
**Post date:** [August 31, 2010, 4:05pm UTC](https://www.ruby-forum.com/t/multipart-email-html-document-files/193970/7 "2010-08-31T16:05:14Z")

</div>

Peter De Berdt wrote:

> On 31 Aug 2010, at 13:10, Pale H. wrote:
> 
> > > specify each of the parts (plain, html, attachments etc.)
> > > 
> > > Fred
> > 
> > Thank you for your replies, both of you. It is true that I need to  
> > split  
> > the email into different parts but the syntax is losing me.
> 
> It’s a real pain, even in Rails 3 with the new mail gem (although it’s  
> already a lot more streamlined). And be happy you don’t want to bring  
> inline images to the mix.
> 
> This might help:  
> [http://www.wetware.co.nz/blog/2010/06/sending-emails-with-rails-multipart-html-plain-with-attachments/](http://www.wetware.co.nz/blog/2010/06/sending-emails-with-rails-multipart-html-plain-with-attachments/)  
> [http://iamwil.posterous.com/2312983](http://iamwil.posterous.com/2312983)
> 
> Best regards
> 
> Peter De Berdt

Those links helped me out and solved my problem; I just needed the  
syntax. The logic wasn’t a problem so that cleared it up for me - thank  
you.
