[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

How to get 'NewMail' event from Outlook

Chuankai Lin

6/12/2008 12:44:00 AM

Hi,

I wrote the this script to get the 'NewMail' event from Outlook

================newmail.rb=======================
require 'win32ole'

ol = WIN32OLE.new('Outlook.Application')
ev = WIN32OLE_EVENT.new(ol, 'ApplicationEvents')
ev.on_event("NewMail") { puts 'NewMail!' }

k = gets

=================================================

But when I ran the script and tried to send a mail to myself, the
outlook hung. If I terminate my ruby program, then the outlook comes
back.

The script seems to affect the execution of outlook.

Does anyone have any idea? Is there anything wroing in my code.

Thanks for your time.

BR,
cklin
--
Posted via http://www.ruby-....

2 Answers

Florian Gilcher

6/12/2008 5:58:00 PM

0

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


On Jun 12, 2008, at 2:43 AM, Chuankai Lin wrote:

> Hi,
>
> I wrote the this script to get the 'NewMail' event from Outlook
>
> ================newmail.rb=======================
> require 'win32ole'
>
> ol = WIN32OLE.new('Outlook.Application')
> ev = WIN32OLE_EVENT.new(ol, 'ApplicationEvents')
> ev.on_event("NewMail") { puts 'NewMail!' }
>
> k = gets
>
> =================================================

I don't know you system, but what should k = gets do? This usually
lets you script wait for input on $stdin (whatever that may be). This
is no way to set you script into "waiting mode"!

Regards,
Florian Gilcher
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.8 (Darwin)

iEYEARECAAYFAkhRY60ACgkQJA/zY0IIRZYPYgCgkSRA2FD4KcMhV+a7qj4k04gM
02kAnRyVptkRJgTffgDO5MQJYdczK657
=cckK
-----END PGP SIGNATURE-----

Chuankai Lin

6/15/2008 3:20:00 PM

0

The answer is found by my friend. The script below works on my windows
box:

=========================================
require 'win32ole'

ol = WIN32OLE.new('Outlook.Application')
#puts ol.Explorers.Item(1)
#puts ol.ActiveExplorer.CurrentFolder.UnReadItemCount
ev = WIN32OLE_EVENT.new(ol, 'ApplicationEvents')
puts ol.GetNamespace("MAPI").GetDefaultFolder(6).UnReadItemCount
ev.on_event("NewMail") { puts 'NewMail!' }

loop { WIN32OLE_EVENT.message_loop }
=========================================
Florian Gilcher wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
>
> On Jun 12, 2008, at 2:43 AM, Chuankai Lin wrote:
>
>>
>> k = gets
>>
>> =================================================
>
> I don't know you system, but what should k = gets do? This usually
> lets you script wait for input on $stdin (whatever that may be). This
> is no way to set you script into "waiting mode"!
>
> Regards,
> Florian Gilcher
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.8 (Darwin)
>
> iEYEARECAAYFAkhRY60ACgkQJA/zY0IIRZYPYgCgkSRA2FD4KcMhV+a7qj4k04gM
> 02kAnRyVptkRJgTffgDO5MQJYdczK657
> =cckK
> -----END PGP SIGNATURE-----

--
Posted via http://www.ruby-....