# Retrieving yahoo! mail?

**URL:** <https://www.ruby-forum.com/t/retrieving-yahoo-mail/114844>\
**Category:** Ruby\
**Created:** [September 18, 2007, 1:30am UTC](https://www.ruby-forum.com/t/retrieving-yahoo-mail/114844 "2007-09-18T01:30:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![7stud](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/7/57b2e6/32.png) [@7stud](https://www.ruby-forum.com/u/7stud)\
**Post date:** [September 18, 2007, 1:30am UTC](https://www.ruby-forum.com/t/retrieving-yahoo-mail/114844/1 "2007-09-18T01:30:13Z")

</div>

Hi,

As an exercise, I’m trying to use Net::HTTP to retrieve my yahoo mail.  
I looked at the source html for the yahoo mail login page at:

> **[Yahoo Mail - Organized Email](https://mail.yahoo.com/)**
>
> It's time to get stuff done with Yahoo Mail. Just add your Gmail, Outlook, AOL or Yahoo Mail to get going. We automatically organize all the things life throws at you, like receipts and attachments, so you can find what you need fast. Plus, we've got...

On that page is a form with two form fields for obtaining the username  
and password. Those form fields have the name attributes:

login  
passwd

The form data is submitted to to the following url(which is specified in  
the form’s action attribute):

action=“[Yahoo](https://login.yahoo.com/config/login?)”

I’m using the following general format for posting form data with ruby  
1.8.2, which I got from the comments at the top of net/http.rb:

require “net/http”  
require “uri”

url = URI.parse(“[Yahoo](https://login.yahoo.com/config/login?)”)

Net::HTTP.start(“[https://login.yahoo.com](https://login.yahoo.com)”, 80) do |http|  
headers2 = {“Host”, “[www.yahoo.com](http://www.yahoo.com)”}

```
response = http.post("/config/login?", "login=me&passwd=pword",

```

headers2)

```
puts response.message
puts response.code
response.each_header do |header, val|
    puts "#{header}: #{val}"
end

```

end

During testing, I found out that if I didn’t specify a hash containing  
headers, I would get a Bad Request error:

Bad Request  
400

With some further testing, I discovered that the Host header is the only  
one that is necessary to get a response. Here is the output from the  
response:

Found  
302  
connection: close  
content-type: text/html; charset=UTF-8  
date: Mon, 17 Sep 2007 23:11:06 GMT  
server: Apache  
content-length: 0  
location:  
[http://earthlink-help.com/?AddInType=Bdns&Version=1.2.0el&FailureMode=1&ParticipantID=xj6e3468k634hy3945zg3zkhfn7zfgf6&ClientLocation=us&FailedURI=http%3A%2F%2Fwww.yahoo.com%2Fconfig%2Flogin%3F](http://earthlink-help.com/?AddInType=Bdns&Version=1.2.0el&FailureMode=1&ParticipantID=xj6e3468k634hy3945zg3zkhfn7zfgf6&ClientLocation=us&FailedURI=http%3A%2F%2Fwww.yahoo.com%2Fconfig%2Flogin%3F)

I get the same response output no matter what headers I include, e.g.:

headers = {“Accept”, “text/html”,  
“Content Type”, “application/x-www-form-urlencoded”,  
“Content-Length”, “40”,  
“Host”, “[www.yahoo.com](http://www.yahoo.com)”  
}

Here’s a description of a 302 response:

* * *

302 Found

The requested resource resides temporarily under a different URI. Since  
the redirection might be altered on occasion, the client SHOULD continue  
to use the Request-URI for future requests. This response is only  
cacheable if indicated by a Cache-Control or Expires header field.

The temporary URI SHOULD be given by the Location field in the response.  
Unless the request method was HEAD, the entity of the response SHOULD  
contain a short hypertext note with a hyperlink to the new URI(s).

## If the 302 status code is received in response to a request other than GET or HEAD, the user agent MUST NOT automatically redirect the request unless it can be confirmed by the user, since this might change the conditions under which the request was issued.

I thought I would be able to get the Location header and proceed from  
there. But I pasted the location url into my browser, and it’s an  
earthlink error page. So, it seems something must be wrong with my  
request.

I’m not sure if I’m using the correct url for the Host header and  
whether that may be the source of the problem. Can anyone point me in  
the right direction to proceed from here? I created a yahoo mail  
account just for testing this program, so feel free to use the account.  
The login name and password are in the code.

Thanks.

---

<div class="post-metadata">

**Author:** ![7stud](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/7/57b2e6/32.png) [@7stud](https://www.ruby-forum.com/u/7stud)\
**Post date:** [September 18, 2007, 2:04am UTC](https://www.ruby-forum.com/t/retrieving-yahoo-mail/114844/2 "2007-09-18T02:04:23Z")

</div>

7stud – wrote:

> The login name and password are in the code.
> 
> Thanks.

Whoops. Here is the account info:

response = http.post("/config/login?",  
“login=rubytestmail&passwd=rubyruby”)
