# Accessing just the body of email in text format?

**URL:** <https://www.ruby-forum.com/t/accessing-just-the-body-of-email-in-text-format/69544>\
**Category:** Rails\
**Created:** [February 17, 2006, 6:57am UTC](https://www.ruby-forum.com/t/accessing-just-the-body-of-email-in-text-format/69544 "2006-02-17T06:57:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![softwareengineer\_99](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b782af/32.png) [@softwareengineer\_99](https://www.ruby-forum.com/u/softwareengineer_99)\
**Post date:** [February 17, 2006, 6:57am UTC](https://www.ruby-forum.com/t/accessing-just-the-body-of-email-in-text-format/69544/1 "2006-02-17T06:57:57Z")

</div>

I am interested in accessing the body of the email in text format using  
IMAP to receive emails.

So far I have tried the following

```
  #body = imap.fetch(message_id, "BODY[TEXT]")
  #body = imap.fetch(message_id, ["BODY[]"])[0].attr['BODY[]']

```

But both of the above give me body text + the headers including  
Content-Type etc. How can I access just the body in text format.

I appreciate your assistance.

Thanks  
Frank

---

<div class="post-metadata">

**Author:** ![softwareengineer\_99](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b782af/32.png) [@softwareengineer\_99](https://www.ruby-forum.com/u/softwareengineer_99)\
**Post date:** [February 17, 2006, 7:28am UTC](https://www.ruby-forum.com/t/accessing-just-the-body-of-email-in-text-format/69544/2 "2006-02-17T07:28:08Z")

</div>

I have gotten to the part where I can access the body of the email with

# email.body

after passing it to my receiver function using

body = imap.fetch(message\_id, [“BODY[]”])[0].attr[‘BODY[]’]

The problem now is that I get both a text version of the email as well  
as the HTML version of the email.

How can I just get the text version of the email.

Thanks  
Frank

softwareengineer 99 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote: I am  
interested in accessing the body of the email in text format using IMAP  
to receive emails.

So far I have tried the following

```
  #body = imap.fetch(message_id, "BODY[TEXT]")
  #body = imap.fetch(message_id, ["BODY[]"])[0].attr['BODY[]']

```

But both of the above give me body text + the headers including  
Content-Type etc. How can I access just the body in text format.

I appreciate your assistance.

Thanks  
Frank

* * *

Relax. Yahoo! Mail virus scanning helps detect nasty  
viruses!\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
Rails mailing list  
removed\_email\_address@domain.invalid  
[http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

---

<div class="post-metadata">

**Author:** ![softwareengineer\_99](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/b782af/32.png) [@softwareengineer\_99](https://www.ruby-forum.com/u/softwareengineer_99)\
**Post date:** [February 17, 2006, 6:51pm UTC](https://www.ruby-forum.com/t/accessing-just-the-body-of-email-in-text-format/69544/3 "2006-02-17T18:51:56Z")

</div>

Experts, I appreciate any pointers you can provide on how I can  
access/split the message in text form and/or extract the text only  
version from text and html?

Currently I am able to get to this part:

* * *

This is my first blog post via email and I am happy about it.

* * *

## Yahoo! Mail Use Photomail to share photos without annoying attachments. This is my first blog post via email and I am happy about it.

* * *
 Yahoo! Mail  
  
[Use  
Photomail](http://pa.yahoo.com/*http://us.rd.yahoo.com/evt=38867/*http://photomail.mail.yahoo.com) to share photos without annoying attachments.

As you can see the HTML post follows the text post in the same  
message. How can I leave the duplicate HTML copy out?

Many Thanks for your assistance  
Frank

softwareengineer 99 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote: I have gotten  
to the part where I can access the body of the email with

# email.body

after passing it to my receiver function using

body = imap.fetch(message\_id, [“BODY[]”])[0].attr[‘BODY[]’]

The problem now is that I get both a text version of the email as well  
as the HTML version of the email.

How can I just get the text version of the email.

Thanks  
Frank

softwareengineer 99 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote: I am  
interested in accessing the body of the email in text format using IMAP  
to receive emails.

So far I have tried the following

```
  #body = imap.fetch(message_id, "BODY[TEXT]")
  #body = imap.fetch(message_id, ["BODY[]"])[0].attr['BODY[]']

```

But both of the above give me body t ext + the headers including  
Content-Type etc. How can I access just the body in text format.

I appreciate your assistance.

Thanks  
Frank

* * *

Relax. Yahoo! Mail virus scanning helps detect nasty  
viruses!\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_  
Rails mailing list  
removed\_email\_address@domain.invalid  
[http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

* * *

What are the most popular cars? Find out at Yahoo! Autos

* * *

Rails mailing list  
removed\_email\_address@domain.invalid  
[http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)
