How to get 'NewMail' event from Outlook

C

Chuankai Lin

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
 
F

Florian Gilcher

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


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-----
 
C

Chuankai Lin

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 }
=========================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,189
Members
46,735
Latest member
HikmatRamazanov

Latest Threads

Top