Getting Hash value instead of actual link from email.

170 views
Skip to first unread message

Bhavesh

unread,
Apr 24, 2012, 4:28:08 PM4/24/12
to Watir General
Hi,

Im trying to access links inside an email.

Im am not using Gem “mail”.

Im doing very simple stuff here.

Just getting unread email from the mailbox and then getting the links
present inside that email.

When I try to get email bocdy, I get without error.

But similarly when I try to get links present inside that email, it
shows Hash value instead of actual links.

Code is :

#Getting email body/Links of unread email
inbox = mapi.GetDefaultFolder(6)
inbox.Items.each do |message|
#puts message.body if message.Unread
puts message.Links if message.Unread

What I have to change to get the actual links.

Bhavesh

Chuck van der Linden

unread,
Apr 24, 2012, 4:32:00 PM4/24/12
to watir-...@googlegroups.com
I see no watir in your code below, why are you posting this question here? 

Chuck van der Linden

unread,
Apr 24, 2012, 4:36:46 PM4/24/12
to watir-...@googlegroups.com
The mail gem has it's own google group, the link is in the readme  look here:  https://github.com/mikel/mail/

That would be the better place to ask your question

Bhavesh

unread,
Apr 24, 2012, 4:49:14 PM4/24/12
to Watir General
Yes, im doing this in watir.

Instead of using mail gem, im using this method to retrive emails.

I dont want to install gem "mail".

I need to know how to get values instead of these hash values.

Bhavesh

Chuck van der Linden

unread,
Apr 24, 2012, 5:14:13 PM4/24/12
to watir-...@googlegroups.com
Then show us some example HTML and some code that is using watir that shows what you are trying to do.

I have for example zero idea what mail system you are even trying to access, you've given us pretty much zero info other than the code you want to replace (which itself has very little info we could infer). 

if you are expecting the folks here to write your code for you, that's not going to happen.  we'll provide guidance, advice, and try to get you unstuck etc.  but we're not going to port code from some other gem over to use watir starting from nothing.  Nearly all of us have our hands full doing our own work, and little time to do someone elses work for free.  

If you have not already done so, spend some time in the watir tutorial http://wiki.openqa.org/display/WTR/Tutorial  or with the Watir Book http://watir.com/book/ (which tends to be more current than the wiki tutorial) to get you started. 

Bhavesh

unread,
Apr 24, 2012, 6:44:45 PM4/24/12
to Watir General
Hi Chuck,

I don't expect people to write an code for me.

I have already posted the code which i am using in my script in my
first Post.

Code is :

outlook = WIN32OLE.new('Outlook.Application')
mapi = outlook.GetNameSpace('MAPI')
folders = mapi.Folders
new_messages = 0

#Getting email body/Links of unread email
inbox = mapi.GetDefaultFolder(6)
inbox.Items.each do |message|
#puts message.body if message.Unread
puts message.Links if message.Unread

This is all i am doing.

And it is working too....

I have Outlook opened and it is retriving first unread emial which i
want.

So i have written an code and it is working.

Question is, when i try to retrive email body, it works and retrive it
without error.

But when i try to retrive links which are in email, it shows Hash
values instead of actual links.

Here is the output :

#<WIN32OLE:0x171bda8>
.
Finished in 0.812500 seconds.


So i have a doubt, im not clear and therefore im putting my question.
i dont expect anybody to write me a code.

I clearly written in my Post that im not using "mail" gem, im doing
normal stuf related with emails.

I hope that explains my concerns.

thanks
bhavesh



On Apr 24, 2:14 pm, Chuck van der Linden <sqa...@gmail.com> wrote:
> Then show us some example HTML and some code that is using watir that shows
> what you are trying to do.
>
> I have for example zero idea what mail system you are even trying to
> access, you've given us pretty much zero info other than the code you want
> to replace (which itself has very little info we could infer).
>
> if you are expecting the folks here to write your code for you, that's not
> going to happen.  we'll provide guidance, advice, and try to get you
> unstuck etc.  but we're not going to port code from some other gem over to
> use watir starting from nothing.  Nearly all of us have our hands full
> doing our own work, and little time to do someone elses work for free.
>
> If you have not already done so, spend some time in the watir tutorialhttp://wiki.openqa.org/display/WTR/Tutorial or with the Watir Bookhttp://watir.com/book/(which tends to be more current than the wiki

Chuck van der Linden

unread,
Apr 24, 2012, 7:03:34 PM4/24/12
to watir-...@googlegroups.com
There is not a single line of code in what you provided below that is using Watir. 

Watir is Web Application Testing in Ruby, it is for driving web browsers and automating web applications.

"I have outlook open"   Outlook is a native application, not a web application.  YOU CANNOT DRIVE OUTLOOK WITH WATIR
There is 'OWA or Outlook Web Access' but I can tell you are not using it because of this line of ruby code "WIN32OLE.new('Outlook.Application')"

You need to ask questions of this sort in a more general forum for ruby, or perhaps on stackoverflow with appropriate tags (such as 'ruby' and 'mapi' )

If you were using watir, and a web application we'd be glad to help you.  but you are not using watir, nor are you using a web application, so this is not the place to ask for help with the problems you are having

I'd suggest doing some Ruby tutorials, or perhaps getting a good book on basic ruby scripting such as 'everyday scripting in ruby'  you can get it as an ebook and be working on it minutes after you buy it.

Bhavesh

unread,
Apr 24, 2012, 7:31:14 PM4/24/12
to Watir General
Hi chuck,

You are still not getting me.

Im am using Watir, and an webapplicaiton.

From my application, i can send notification.

Once notification is received in Outlook Inbox, i have to get the
links in that emails.

I automated using Watir till i can send the notification on an web
application.

I have written code to get emails also from the Outlook in watir
script [which i have pasted in last thread].

Now im getting some different result which i dont understand as why
hash value is returned instead of actual links.

Hence i posted the query in Watir forum.

This thread is now going in some different direction instead of my
problem.

Since im not using "mail" gem, i cannot post an query to ruby-mail
forum.

this is simple WATIR script.

Here is the Snapshot of the full script.

######################

# encoding: utf-8

$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '../..') if $0 ==
__FILE__

require 'Lib/KazeonCommon/BasicMethodLibrary'
require 'Lib/KazeonCommon/LegalUIMethodLibrary'
require 'Lib/KazeonCommon/WebAutosetup.rb'

class Mail < Test::Unit::TestCase

def test_0010

$ie.goto($legalLink)
sleep(5)
kazeonLegalLogin("LEGALUI",domain="Local",
loginName="legaladmin")
#kazeonLegalLogin("LEGALUI",domain="Local",
loginName="legaladmin")
sleep(10)
printTestCaseInfo("LEGALUI0007", "create a case with case id,
status 'open', value in Description and value in Responsible
Attorney")
#puts "Select and add reviewers in legal"
# $ie.div(:class => "x-grid3-cell-inner x-grid3-col-
reviewername", :text => "bhavesh").click
# sleep(5)
# $ie.link(:id, "button2").click
# sleep(5)
sleep(5)
puts "Select Active Case"
selectActiveCase("case4")
clickOkButton()
puts "Select Notify Custodian Button"
$_ = $ie.html
$ie.button(:class, "x-btn-text sendemail").click
sleep(5)
puts "Select Add Receipient Button"
$ie.button(:class => "x-btn-text addReviewer", :index => 2).click
sleep(5)
puts "Select Non Ad User Radio Button"
$ie.radio(:value, "nonADUser").click
sleep(5)
puts "Enter Username"
$ie.text_field(:id, "lookupFilter").set("bhavesh...@emc.com")
sleep(5)
puts "Click Go Button"
#$ie.link(:id, "getData").click
sleep(5)
puts "Select User"
$ie.div(:class => "x-grid3-cell-inner x-grid3-col-2", :text =>
"bhavesh...@emc.com").flash
sleep(2)
$ie.div(:class => "x-grid3-cell-inner x-grid3-col-2", :text =>
"bhavesh...@emc.com").left_click
sleep(5)
puts "Select Add selected Button"
$ie.button(:value, "Add Selected").click
sleep(3)
puts "Select Close Button"
$ie.button(:value, "Close").click
sleep(5)
puts "Select Send Notification button"
$ie.button(:text, "Send Notifications").click
sleep(10)
puts "Done"

outlook = WIN32OLE.new('Outlook.Application')
mapi = outlook.GetNameSpace('MAPI')
folders = mapi.Folders
new_messages = 0

#Getting email body of unred email
inbox = mapi.GetDefaultFolder(6)
inbox.Items.each do |message|
#puts message.body if message.Unread
puts message.Links if message.Unread

end
end


end
##################

Last line im getting unexpected result, for which i posted the query.

I dont want to put all code in the post, otherwise it is very big .

I hope im clear this time.

bhavesh
> > tutorialhttp://wiki.openqa.org/display/WTR/Tutorialor with the Watir
> > Bookhttp://watir.com/book/(which<http://watir.com/book/%28which> tends

Bhavesh

unread,
Apr 24, 2012, 11:13:41 PM4/24/12
to Watir General
OK, i got the solution.

I pattern matched the link text from the message body.

After grabbing the link text, i can use it to navigate.

So all ok now.

Only thing if someone can help is, i got the email body but as same
time i want to mark that email as "read" instead of "unread", so that
next time when i have another new email, i get content from that new
email and previous all emails are in read state.

Does anyone knows it?

Bhavesh
>           $ie.text_field(:id, "lookupFilter").set("bhavesh.sha...@emc.com")
>           sleep(5)
>           puts "Click Go Button"
>           #$ie.link(:id, "getData").click
>           sleep(5)
>           puts "Select User"
>           $ie.div(:class => "x-grid3-cell-inner x-grid3-col-2", :text =>
> "bhavesh.sha...@emc.com").flash
>           sleep(2)
>           $ie.div(:class => "x-grid3-cell-inner x-grid3-col-2", :text =>
> "bhavesh.sha...@emc.com").left_click
> > > tutorialhttp://wiki.openqa.org/display/WTR/Tutorialorwith the Watir

Željko Filipin

unread,
Apr 25, 2012, 3:31:22 AM4/25/12
to watir-...@googlegroups.com
On Wed, Apr 25, 2012 at 5:13 AM, Bhavesh <bhavesh...@yahoo.com> wrote:
> Only thing if someone can help is,  i got the email body  but as same
> time i want to mark that email as "read" instead of "unread", so that
> next time when i have another new email, i get content from that new
> email and previous all emails are in read state.

I guess Chuck is trying to tell you that Watir automates browsers, and you want to automate Outlook. It does not matter if you are using Watir to send mail, you have to use another tool to read mail. Are you aware that you are not using Watir to drive Outlook? (You are using Ruby.)

I have done a lot of mail sending/reading/parsing and I would highly suggest that you use another tool (like mail gem) for that, instead of automating Outlook. If you have questions on how to do that, I would be glad to help.

Željko
--
watir.com/book - author

Bhavesh

unread,
Apr 25, 2012, 11:57:47 AM4/25/12
to Watir General
Hi Zeljko,

Thanks. You are always helpful.

I think you are on vacation Yesterday, otherwise i could have done it
yesterday.

I tried doing the stuff using "mail" gem, but it didn't worked [Reason
is : im not much aware of this gem].

I posted query on ruby mail forum too, but no replies to solve my
problem.

If i use "mail" gem, then when i try to access new unread email, it
fails, it always returns first mail whether it is read or unread.

Here is what i posted on mail forum :

######################

Hi,
I added following code in my WATIR script, and abel to get first
email from my Inbox
require 'mail'
require 'openssl'
Mail.defaults do
retriever_method :pop3, :address =>
"email.someemail.com",
:port => 995,
:user_name => 'domain/username',
:password => 'pwd',
:enable_ssl => true
end
puts Mail.first

I am new to this forum and have following questions :

1. How can I get all the unread emails ?
2. How can I get all links that are present inside emails? or
mail message body from the email?
3. Can I click Links present inside an email? [This i can do once
i have an link]
4. How can I get emails from a specific folder, if I have
subfolders?

If some one can help me, then that will be nice.

Thanks in advance.
Bhavesh

###########################

The webpage for mail gem states that if you use mail.first, it will
return first unread email, so oi did that.

When i have not received any input/help here, i thought i can use
Autoit, to get it working from outlook.

With autoit, still im struggling to mark mail as "read" from "unread"
once i get details [mail body] from the mail.

And if i use mail gem, then in that case, im totally stuck.

If you can help me on "mail" gem, with questions i posted, then it
will be very helpfull. Also if you tell me how to mark mail as "read"
from "unread" when i use mail gem.

thanks
Bhavesh


On Apr 25, 12:31 am, Željko Filipin <zeljko.fili...@gmail.com> wrote:

Željko Filipin

unread,
Apr 25, 2012, 12:15:20 PM4/25/12
to watir-...@googlegroups.com
Comments are inline.

On Wed, Apr 25, 2012 at 5:57 PM, Bhavesh <bhavesh...@yahoo.com> wrote:
> I think you are on vacation Yesterday, otherwise i could have done it
> yesterday.

Not on vacation, just really busy. :)


> If i use "mail" gem, then when i try to access new unread email, it
> fails, it always returns first mail whether it is read or unread.

As far as I remember, when you get mail via POP3 (as you are doing) there is no way to mark an e-mail message as read. You can just download it and delete it. You should use IMAP if you want to mark message as read.

> 1.      How can I get all the unread emails ?

Looks like this should do it:

Mail.all

More info:

http://rubydoc.info/gems/mail/Mail/IMAP
http://rubydoc.info/gems/mail/Mail/POP3

> 2.      How can I get all links that are present inside emails?

I do not think mail gem provides that functionality.

> or mail message body from the email?

mail.body.decoded

More info:


 
> 3.      Can I click Links present inside an email? [This i can do once
> i have an link]

No, but you can save a link in a variable and than open the page with Watir. You have to understand that mail gem and watir gem are really focused. Mail gem just reads, sends and receives mail, does not know anything about browsers or links. Watir gem just drives browsers, does not know anything about e-mail.

> 4.      How can I get emails from a specific folder, if I have
> subfolders?

Do you want to access e-mail messages on a server, or on your local machine?

Željko

Bhavesh

unread,
Apr 25, 2012, 12:39:06 PM4/25/12
to Watir General
Thanks .

I will write the code around and get it working.

For subfolders, actually inside Inbox, there are sub folder where
specific mails are getting collected based on the policy/rules.

That is the reason i need to get the mails from subfolder, but let me
try it out.

thanks
bhavesh

On Apr 25, 9:15 am, Željko Filipin <zeljko.fili...@gmail.com> wrote:
> Comments are inline.
>
> On Wed, Apr 25, 2012 at 5:57 PM, Bhavesh <bhavesh1_sha...@yahoo.com> wrote:
> > I think you are on vacation Yesterday, otherwise i could have done it
> > yesterday.
>
> Not on vacation, just really busy. :)
>
> > If i use "mail" gem, then when i try to access new unread email, it
> > fails, it always returns first mail whether it is read or unread.
>
> As far as I remember, when you get mail via POP3 (as you are doing) there
> is no way to mark an e-mail message as read. You can just download it and
> delete it. You should use IMAP if you want to mark message as read.
>
> > 1.      How can I get all the unread emails ?
>
> Looks like this should do it:
>
> Mail.all
>
> More info:
>
> http://rubydoc.info/gems/mail/Mail/IMAPhttp://rubydoc.info/gems/mail/Mail/POP3

Željko Filipin

unread,
Apr 25, 2012, 12:41:23 PM4/25/12
to watir-...@googlegroups.com
On Wed, Apr 25, 2012 at 6:39 PM, Bhavesh <bhavesh...@yahoo.com> wrote:
> For subfolders, actually inside Inbox, there are sub folder where
> specific mails are getting collected based on the policy/rules.

Are you using Gmail?

Željko

Chuck van der Linden

unread,
Apr 25, 2012, 12:54:57 PM4/25/12
to watir-...@googlegroups.com


On Tuesday, April 24, 2012 4:31:14 PM UTC-7, Bhavesh wrote:
Hi chuck,

You are still not getting me.

Im am using Watir, and an webapplicaiton.

From my application, i can send notification.

Once notification is received in Outlook Inbox, i have to get the
links in that emails.

I automated using Watir till i can send the notification on an web
application.

I have written code to get emails also from the Outlook in watir
script [which i have pasted in last thread]. 

Thanks for providing that detail, if you had started out saying something to that effect then what you were trying to do would have been a lot clearer, instead of just presenting us with some code that has nothing to do with watir and no context to how this relates to work you are doing in watir.   That little bit of background, a single sentence such as "I am generating an email via automating a web app with watir, but now I need to validate the content of the resulting mail, especially links within the mail body" would have greatly helped people to understand the overall nature of the problem.  Then you could go into the fact you are getting a hash value and not the link and does anyone know how you would get the link, or iterate the hashes to get the info you need.

Still, and as Zeljko has explained also, this is really not the forum for help with automating outlook or pop3 mail access.  I now understand you are using watir to send the mail, but your challenge at this point, how to receive and verify the mail contents, has little to do with watir unless you were using something like OWA, Gmail or another web interface to an email system to handle the mail.

I would strongly suggest moving this to StackOverflow, and putting some appropriate tags on the question.  You can post a link to it here so anyone else with a similar problem (or time to assist you) can follow over to it.  You are far more likely to find more folks with experience dealing with email via ruby, and get some good answers to your question (and the code can be properly formatted, questions edited and updated as well as answers).  You can also post a link to the question on the google group that deals with the mail gem.   I really think that might be a better way for you to get this issue resolved.   At the very least you are far more likely to find people with experience doing that kind of coding, than asking the question here in the Watir group since at this point your challenge is not really with watir.

Bhavesh

unread,
Apr 25, 2012, 1:13:13 PM4/25/12
to Watir General
Thats correct, im struggling on mail when i use mail gem.

I already posted an query on :

http://groups.google.com/group/mail-ruby

but no relies.

I posted on ruby forum also, but no replies.

Let me try to do it using stackoverflow.

By the way zeljko, im still not able to get the unread emails if i
use Mail.all, mail.first or mail.,last.

Bhavesh

Željko Filipin

unread,
Apr 25, 2012, 1:17:55 PM4/25/12
to watir-...@googlegroups.com
On Wed, Apr 25, 2012 at 7:13 PM, Bhavesh <bhavesh...@yahoo.com> wrote:
> By the way zeljko,   im still not able to get the unread emails if i
> use Mail.all, mail.first or mail.,last.

You will have to provide more information. I am monitoring mail gem list so feel free to post there.

Željko

Bhavesh

unread,
Apr 25, 2012, 1:26:23 PM4/25/12
to Watir General
OK, i will update my query with more details in that forum.

On Apr 25, 10:17 am, Željko Filipin <zeljko.fili...@gmail.com> wrote:

Bhavesh

unread,
Apr 25, 2012, 7:06:26 PM4/25/12
to Watir General
No..im not using gmail.

im using my own corporate emial account.

I already posted the query for this on :

http://groups.google.com/group/mail-ruby

Bhavesh

Željko Filipin

unread,
Apr 26, 2012, 3:55:01 AM4/26/12
to watir-...@googlegroups.com
On Thu, Apr 26, 2012 at 1:06 AM, Bhavesh <bhavesh...@yahoo.com> wrote:
> I already posted the query for this on :
> http://groups.google.com/group/mail-ruby

I will reply there.

Željko
Reply all
Reply to author
Forward
0 new messages