开发者

programmatically yahoo mail navigation

I want to write a program which can save latest 10 mails from my yahoo email account as text files given yahoo username and pwd.

I tried using python ie = Dispatch("InternetExplorer.Application")

I was able to sign-in but could not use ie.doc开发者_Go百科ument.getElementsByName(" ") ie.document.getElementsById(" ") to read emails

Any suggestion?

Thanks.


You can access a basic Yahoo account via IMAP by issuing a non-standard ID ("GUID" "1") command. The following code illustrates this by printing out the message ids of all your new emails:

require 'net/imap'
Net::IMAP.debug = true
conn = Net::IMAP.new('imap.mail.yahoo.com', 143, false)
conn.instance_eval { send_command('ID ("GUID" "1")') }
conn.authenticate('LOGIN', ARGV[0], ARGV[1] )
conn.select("INBOX")
uids = conn.uid_search(['NEW'])
puts uids.join(',')
conn.logout
conn.disconnect

Be aware that there is a bug in ruby net/imap library. You need to apply the patch referenced here:

Connecting to Yahoo! mail from Ruby


Wouldn't it be easier to do this with POP3/IMAP? Just fetch the last 10 mails and leave the on the server?

This way you are not dependent on the Yahoo website. (if it changes your code will break since its dependent on the UI).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜