win32ole, outlook, ruby 1.8

G

Greg Brondo

I'm using ruby 1.8 on Windows via rubyinstaller accessing outlook with
win32ole. When I create an outlook.application object and then create a
message instance I'm not able to 'Move' or 'Delete' the message even though
the methods are listed in ole_methods. However, many other methods work
like a champ.

Any ideas?

Greg Brondo
 
G

Greg Brondo

Here's the error I receive when attempting a listed method:

WIN32OLERuntimeError: Move
OLE error code:0 in <Unknown>
<No Description>
HRESULT error code:0x8002000f
Parameter not optional
from (irb):16:in `method_missing'
from (irb):16
from :0


However, methods like 'Copy' work just fine.

Thanks,
Greg B.
 
E

Eric Hodel

--aPdhxNJGSeOG9wFI
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable
Here's the error I receive when attempting a listed method:
=20
WIN32OLERuntimeError: Move
OLE error code:0 in <Unknown>
<No Description>
HRESULT error code:0x8002000f
Parameter not optional

Are you specifying the destination folder as the argument?
from (irb):16:in `method_missing'
from (irb):16
from :0
=20
=20
However, methods like 'Copy' work just fine.

How about a snippet of the code you're using?

--=20
Eric Hodel - (e-mail address removed) - http://segment7.net
All messages signed with fingerprint:
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04


--aPdhxNJGSeOG9wFI
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (FreeBSD)

iD8DBQE/5zMRMypVHHlsnwQRAuz7AKDE9yyTMadqlJ3EAn9cOZJFaYARMQCeKHqi
xJbJ4wXBFncPTirJwc/fJe0=
=wKyY
-----END PGP SIGNATURE-----

--aPdhxNJGSeOG9wFI--
 
G

Greg Brondo

ACK! Never mind. Figured it out. The move method takes an outlook folder
object as a parameter...Yahoo!!!

Greg B.
 
J

James Toomey

This code successfully deleted the email with the subject line "Delete
Me" when I tried it:

require 'win32ole'
olApp = WIN32OLE.new('Outlook.Application')
#The number 6 is the constant olFolderInbox.
inbox = olApp.GetNamespace('MAPI').GetDefaultFolder(6)
emailItems = inbox.Items
emailItems.each {|x|
if x.Subject == 'Delete Me' then
x.Delete
end
}

What does your original code look like?
 
G

Greg Brondo

I figured it out. It needed an outlook folder object for the move to work.
Here's the code:

require 'win32ole'
require 'yaml'

reList = YAML::load(File.open('rSpamAndSpam.re'))

def checkSpam(msgBody, reList)
isSpam = false
reList.each do |re|
if msgBody =~ re
isSpam = true
break
end
end
return isSpam
end

outlookInbox = 6
outlookDeletedItems = 3
objOutlook = WIN32OLE.new('Outlook.Application')
objNameSpace = objOutlook.GetNamespace("MAPI")
objFolder = objNameSpace.GetDefaultFolder(outlookInbox)
delFolder = objNameSpace.GetDefaultFolder(outlookDeletedItems)

objFolder.Items.each do |i|
puts "-" * 60
puts i.Subject
isSpam = checkSpam(i.Body, reList)
puts "Spam = #{isSpam}"
if isSpam
puts i.Body
i.Move(delFolder)
exit
end
end

Thanks!
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top