# Problems with ActionMailer html emails in GMail

**URL:** <https://www.ruby-forum.com/t/problems-with-actionmailer-html-emails-in-gmail/79875>\
**Category:** Rails\
**Created:** [December 20, 2006, 4:09am UTC](https://www.ruby-forum.com/t/problems-with-actionmailer-html-emails-in-gmail/79875 "2006-12-20T04:09:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ericgoodwin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/c68b51/32.png) [@ericgoodwin](https://www.ruby-forum.com/u/ericgoodwin)\
**Post date:** [December 20, 2006, 4:09am UTC](https://www.ruby-forum.com/t/problems-with-actionmailer-html-emails-in-gmail/79875/1 "2006-12-20T04:09:25Z")

</div>

Has anyone gotten an html email to work at [gmail.com](http://gmail.com)? I have probably  
tried every combination under the sun.

Can anyone who has gotten emails to correctly render in GMail post their  
actionmailer method call that sets the multipart content.

I have seen many html formatted emails work in GMail so I know this can  
be done.

-Aryk

---

<div class="post-metadata">

**Author:** ![ericgoodwin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/c68b51/32.png) [@ericgoodwin](https://www.ruby-forum.com/u/ericgoodwin)\
**Post date:** [December 20, 2006, 5:03pm UTC](https://www.ruby-forum.com/t/problems-with-actionmailer-html-emails-in-gmail/79875/2 "2006-12-20T17:03:17Z")

</div>

On Dec 19, 2006, at 10:09 PM, Aryk G. wrote:

> -Aryk

If you happen to be following the Rails Recipes for this, I ran into  
trouble until changing the name of the file from  
“multipart\_alternative.rhtml” to “multipart\_alternative\_html.rhtml”.  
There seemed to be a conflict between the content\_type “multipart/  
alternative” and the file-name-based magic of setting the content type.

I think you can change the name to anything other than  
“multipart\_alternative.rhtml” and get the same results.

Look at the generated email and see if the HTML part is given a MIME  
type of “text/html” or “multipart/alternative”. (I dealt with this  
months ago and don’t recall any more specifics.)

-Rob

# Recipe 67:

# [http://media.pragprog.com/titles/fr\_rr/code/](http://media.pragprog.com/titles/fr_rr/code/)

GracefullyDegradingRichTextEmails/app/models/notifier.rb

#—

# Excerpted from “Rails Recipes”

# We make no guarantees that this code is fit for any purpose.

# Visit [http://www.pragmaticprogrammer.com/titles/fr\_rr](http://www.pragmaticprogrammer.com/titles/fr_rr) for more book

information.  
#—  
class Notifier \< ActionMailer::Base

def multipart\_alternative(recipient, name, sent\_at = Time.now)  
subject “Something for everyone.”  
recipients recipient  
from ‘removed\_email\_address@domain.invalid’  
sent\_on sent\_at  
content\_type “multipart/alternative”

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

```

=\> name)

```
 part :content_type => "text/html",
   :body => render_message("multipart_alternative_html", :name =>

```

name)  
#…^^^^^  
end

def implicit\_multipart(recipient, name, sent\_at = Time.now)  
subject “Something for everyone.”  
recipients recipient  
from ‘removed\_email\_address@domain.invalid’  
sent\_on sent\_at  
body(:name =\> name)  
end

end  
**END**

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

---

<div class="post-metadata">

**Author:** ![ericgoodwin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/c68b51/32.png) [@ericgoodwin](https://www.ruby-forum.com/u/ericgoodwin)\
**Post date:** [December 20, 2006, 8:43pm UTC](https://www.ruby-forum.com/t/problems-with-actionmailer-html-emails-in-gmail/79875/3 "2006-12-20T20:43:37Z")

</div>

Rob,

Thanks for the post. Unfortunately, I tried the code from the recipes  
book and it does work. This is what I currently have:

def invite(email, sender)  
subject sender.full\_name + ’ has invited you to [Mixbook.com](http://Mixbook.com)’  
recipients email  
from ‘removed\_email\_address@domain.invalid’  
sent\_on Time.now  
content\_type “multipart/alternative”  
# headers = {“MIME-Version”=\>1.0}  
# body ‘sender’ =\> sender

```
  part :content_type=> "text/plain",
     :body => render_message("invite_plain",:sender=>sender)

  part :content_type=> "text/html",
     :body => render_message("invite_html", :sender=>sender)

```

end

Bear in mind, that this works in outlook express, just not on GMail’s  
website. Am I somehow coding the email incorrectly. I include style  
information in the actual email because I don’t know where else to put  
it. I doubt that’s the problem though.

---

<div class="post-metadata">

**Author:** ![ericgoodwin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/c68b51/32.png) [@ericgoodwin](https://www.ruby-forum.com/u/ericgoodwin)\
**Post date:** [December 20, 2006, 10:46pm UTC](https://www.ruby-forum.com/t/problems-with-actionmailer-html-emails-in-gmail/79875/4 "2006-12-20T22:46:08Z")

</div>

AYYYYY…

I figured out what I was doing wrong.

Gmail strips your html code of all id and class tags along with  
stylesheets if you those.

You also cant float divs. You need to use archaic tables when dealing  
with gmail and most other clients.
