# Html Email Problem

**URL:** <https://www.ruby-forum.com/t/html-email-problem/60757>\
**Category:** Rails\
**Created:** [May 17, 2006, 8:33am UTC](https://www.ruby-forum.com/t/html-email-problem/60757 "2006-05-17T08:33:53Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Keyon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f05b48/32.png) [@Keyon](https://www.ruby-forum.com/u/Keyon)\
**Post date:** [May 17, 2006, 8:33am UTC](https://www.ruby-forum.com/t/html-email-problem/60757/1 "2006-05-17T08:33:53Z")

</div>

Dear Rubyians,

I am facing problems to send Html Email scnce one month.

I changed the content type is text/html and charecter set “utf-8”

I worte the html code in the confirm.heml in the action mailer folder.

but mail is going with html code

Exapmle:

 code in the  
confirm .html

In the mail i got total code same format what is the wrong

I am also sending the total code in the controller also.

order= Order.find\_session(params[‘ses\_value’])  
order = Order.find\_by\_name(“admin”)  
email = OrderMailer.create\_confirm(order)  
email.set\_content\_type(“text/html”)  
render(:text =\> “

```
” + email.encoded + “
```
”)  
OrderMailer.deliver\_confirm(order)

I also saw the message i.e content type has changed to text/html

What is the problm I searching for solution since one month.

Please give me the references.

With Regards,  
-Keyon

---

<div class="post-metadata">

**Author:** ![Keyon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f05b48/32.png) [@Keyon](https://www.ruby-forum.com/u/Keyon)\
**Post date:** [May 17, 2006, 9:09am UTC](https://www.ruby-forum.com/t/html-email-problem/60757/2 "2006-05-17T09:09:53Z")

</div>

Keyon wrote:

> Dear Rubyians,
> 
> I am facing problems to send Html Email scnce one month.
> 
> I changed the content type is text/html and charecter set “utf-8”
> 
> I worte the html code in the confirm.heml in the action mailer folder.
> 
> but mail is going with html code
> 
> Exapmle:
> 
> code in the  
> confirm .html
> 
> In the mail i got total code same format what is the wrong
> 
> I am also sending the total code in the controller also.
> 
> order= Order.find\_session(params[‘ses\_value’])  
> order = Order.find\_by\_name(“admin”)  
> email = OrderMailer.create\_confirm(order)  
> email.set\_content\_type(“text/html”)  
> render(:text =\> “
> 
> ```
> ” + email.encoded + “
> ```
> ”)  
> OrderMailer.deliver\_confirm(order)
> 
> I also saw the message i.e content type has changed to text/html
> 
> What is the problm I searching for solution since one month.
> 
> Please give me the references.
> 
> With Regards,  
> -Keyon

Hello Keyon !  
I am also fqacing same to send html!

Please help us we are waiting for your solution!

Thanks and Regards  
Santhosh!

---

<div class="post-metadata">

**Author:** ![Keyon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f05b48/32.png) [@Keyon](https://www.ruby-forum.com/u/Keyon)\
**Post date:** [May 17, 2006, 9:49am UTC](https://www.ruby-forum.com/t/html-email-problem/60757/3 "2006-05-17T09:49:57Z")

</div>

You have to use a multipart email - Recipe 67 in the Rails Recipes  
book covers this, and also more information in the ActionMailer docs:  
[http://api.rubyonrails.com/classes/ActionMailer/Base.html](http://api.rubyonrails.com/classes/ActionMailer/Base.html)

Hope that helps,  
David

---

<div class="post-metadata">

**Author:** ![Keyon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f05b48/32.png) [@Keyon](https://www.ruby-forum.com/u/Keyon)\
**Post date:** [May 17, 2006, 1:31pm UTC](https://www.ruby-forum.com/t/html-email-problem/60757/4 "2006-05-17T13:31:30Z")

</div>

David T. wrote:

> You have to use a multipart email - Recipe 67 in the Rails Recipes  
> book covers this, and also more information in the ActionMailer docs:  
> [Peak Obsession](http://api.rubyonrails.com/classes/ActionMailer/Base.html)
> 
> Hope that helps,  
> David

Hi David!  
I followed the same procedure but i did not get the solution please

check this

–mimepart\_446b08d593760\_1f0300f69c183b  
Content-Type: text/plain  
Content-Transfer-Encoding: Quoted-printable  
Content-Disposition: inline

| kkkkkkk |

Thank you for placing the order from The WinIT JEWELS Stores.

–mimepart\_446b08d593760\_1f0300f69c183b  
Content-Type: text/html; charset=utf-8  
Content-Transfer-Encoding: Quoted-printable  
Content-Disposition: inline

| kkkkkkk |

Thank you for placing the order from The WinIT JEWELS Stores.

–mimepart\_446b08d593760\_1f0300f69c183b–

I got this type of out put what is the wrong please help me!  
thanks and Regards,  
-Keyon!

---

<div class="post-metadata">

**Author:** ![Keyon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f05b48/32.png) [@Keyon](https://www.ruby-forum.com/u/Keyon)\
**Post date:** [May 17, 2006, 3:34pm UTC](https://www.ruby-forum.com/t/html-email-problem/60757/5 "2006-05-17T15:34:16Z")

</div>

It looks like the templates for each format aren’t set up properly -  
just to check the obvious, make sure that your plain.rhtml is actually  
just plain text and doesn’t have any HTML tags. I haven’t worked with  
Action Mailer in the past, so I’m not sure how much more help I can  
be.

---

<div class="post-metadata">

**Author:** ![Keyon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f05b48/32.png) [@Keyon](https://www.ruby-forum.com/u/Keyon)\
**Post date:** [July 6, 2006, 5:26pm UTC](https://www.ruby-forum.com/t/html-email-problem/60757/6 "2006-07-06T17:26:44Z")

</div>

> Content-Type: text/html; charset=utf-8  
> Content-Transfer-Encoding: Quoted-printable  
> Content-Disposition: inline
> 
> | kkkkkkk |
> 
> Thank you for placing the order from The WinIT JEWELS Stores.
> 
> –mimepart\_446b08d593760\_1f0300f69c183b–

Hi guys,  
I have the same problem, HTML part ofthe message is in emial twice,  
It looks ok in Apple Mail, but in  
MS Outlook it shows just as html code…

Anybody any idea?  
Miro

---

<div class="post-metadata">

**Author:** ![Keyon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f05b48/32.png) [@Keyon](https://www.ruby-forum.com/u/Keyon)\
**Post date:** [May 17, 2006, 4:11pm UTC](https://www.ruby-forum.com/t/html-email-problem/60757/7 "2006-05-17T16:11:51Z")

</div>

David T. wrote:

> It looks like the templates for each format aren’t set up properly -  
> just to check the obvious, make sure that your plain.rhtml is actually  
> just plain text and doesn’t have any HTML tags. I haven’t worked with  
> Action Mailer in the past, so I’m not sure how much more help I can  
> be.

Please give the right path to find the solution

Thanks and Regards,  
-Keyon

---

<div class="post-metadata">

**Author:** ![Keyon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f05b48/32.png) [@Keyon](https://www.ruby-forum.com/u/Keyon)\
**Post date:** [July 7, 2006, 10:01am UTC](https://www.ruby-forum.com/t/html-email-problem/60757/8 "2006-07-07T10:01:55Z")

</div>

Rob B. \<Rob@…\> writes:

> Well, you don’t give your code, but here’s an example that will  
> generate a multi-part email. Note that if your message template is  
> named “multipart\_alternative.rhtml”, then the content\_type picks it  
> up as the first part and then two more get added.
> 
> If this is your problem, change the name in the render\_message and on  
> the actual file and try it again.
> 
> -Rob

I realized exactly what you said just few hours after my post,  
i renamed my html view file to action\_name\_html.rhtml and all works  
as expected.  
What happened was that AM picked up default html template  
because its name was the same as name of action and then also  
it was added as part of message… through:  
“:body =\> render\_message(“reservation\_email\_plain””

Thanks  
Miro

---

<div class="post-metadata">

**Author:** ![Keyon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/f05b48/32.png) [@Keyon](https://www.ruby-forum.com/u/Keyon)\
**Post date:** [July 6, 2006, 7:50pm UTC](https://www.ruby-forum.com/t/html-email-problem/60757/9 "2006-07-06T19:50:07Z")

</div>

On Jul 6, 2006, at 11:13 AM, Miroslav Zahorak wrote:

> > Content-Type: text/html; charset=utf-8  
> > Hi guys,  
> > I have the same problem, HTML part ofthe message is in emial twice,  
> > It looks ok in Apple Mail, but in  
> > MS Outlook it shows just as html code…
> 
> Anybody any idea?  
> Miro

Well, you don’t give your code, but here’s an example that will  
generate a multi-part email. Note that if your message template is  
named “multipart\_alternative.rhtml”, then the content\_type picks it  
up as the first part and then two more get added.

If this is your problem, change the name in the render\_message and on  
the actual file and try it again.

-Rob

Rob B. [http://agileconsultingllc.com](http://agileconsultingllc.com)  
removed\_email\_address@domain.invalid

### app/models/my\_email\_notifier.rb

class MyEmailNotifier \< ActionMailer::Base

def multipart\_alternative(recipient, extra\_stuff, sent\_at = Time.now)  
subject ‘Cool Multipart Email’  
recipients recipient  
from ‘me@localhost’  
sent\_on sent\_at  
content\_type ‘multipart/alternative’

```
 part :content_type => "text/plain",
  :body => render_message("multipart_alternative_plain", :stuff

```

=\> extra\_stuff)  
part :content\_type =\> “text/html”,  
:body =\> render\_message(“multipart\_alternative\_html”, :stuff =\>  
extra\_stuff)  
end  
end

### app/views/my\_email\_notifier/multipart\_alternative\_plain.rhtml

This is the cool part  
\<%= @stuff %\>

### app/views/my\_email\_notifier/multipart\_alternative\_plain.rhtml

This is the cool part

**\<%=h @stuff %\>**

###
