# Why email part.body doesn't change?

**URL:** <https://www.ruby-forum.com/t/why-email-part-body-doesnt-change/176071>\
**Category:** Ruby\
**Created:** [September 24, 2009, 10:56am UTC](https://www.ruby-forum.com/t/why-email-part-body-doesnt-change/176071 "2009-09-24T10:56:06Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![rabarama](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/839c29/32.png) [@rabarama](https://www.ruby-forum.com/u/rabarama)\
**Post date:** [September 24, 2009, 10:56am UTC](https://www.ruby-forum.com/t/why-email-part-body-doesnt-change/176071/1 "2009-09-24T10:56:06Z")

</div>

this code doesn’t work… why?  
how can i add that head to that body?

head is the html text i want to add to p (a tmail object)

def injecthead(head,p)  
if p.multipart? then  
p.parts.each do |pa|  
injecthead(head,pa)  
end  
else  
if p.content\_type==“text/html” then  
if p.body!=nil then  
startbodytag=p.body.index("\<body")  
endbodytag=(p.body[startbodytag…p.body.length]).index("\>")  
if startbodytag!=nil then  
p.body.insert(startbodytag+endbodytag+1,head)

```
          #i'm sure this code is worked but p.body doesn't change.
          #if i put

```

altbody=p.body.insert(startbodytag+endbodytag+1,head),  
#altbody is the body i want, but if then i write  
p.body=altbody, p.body becames nil

```
        end
      end
    end

  end
end
```
